vulkan: refactor layer extension enumeration
Replace Get*LayerExtensions by a set of new functions that do not
distinguish instance and device layers.
There should be no user-visible change.
Bug: 27911856
Change-Id: Icd98abf51a936769f8f2f218794043b5e2611c5c
diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp
index e3f69fe..6d558ee 100644
--- a/vulkan/libvulkan/api.cpp
+++ b/vulkan/libvulkan/api.cpp
@@ -1123,7 +1123,14 @@
if (pLayerName) {
const VkExtensionProperties* props;
uint32_t count;
- GetInstanceLayerExtensions(pLayerName, &props, &count);
+
+ const Layer* layer = FindLayer(pLayerName);
+ if (layer) {
+ props = GetLayerInstanceExtensions(*layer, count);
+ } else {
+ props = nullptr;
+ count = 0;
+ }
if (!pProperties || *pPropertyCount > count)
*pPropertyCount = count;
@@ -1181,7 +1188,14 @@
if (pLayerName) {
const VkExtensionProperties* props;
uint32_t count;
- GetDeviceLayerExtensions(pLayerName, &props, &count);
+
+ const Layer* layer = FindLayer(pLayerName);
+ if (layer && IsLayerGlobal(*layer)) {
+ props = GetLayerDeviceExtensions(*layer, count);
+ } else {
+ props = nullptr;
+ count = 0;
+ }
if (!pProperties || *pPropertyCount > count)
*pPropertyCount = count;
diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp
index 4363dd8..b7558a2 100644
--- a/vulkan/libvulkan/layers_extensions.cpp
+++ b/vulkan/libvulkan/layers_extensions.cpp
@@ -331,12 +331,7 @@
}
const Layer* FindInstanceLayer(const char* name) {
- auto layer =
- std::find_if(g_instance_layers.cbegin(), g_instance_layers.cend(),
- [=](const Layer& entry) {
- return strcmp(entry.properties.layerName, name) == 0;
- });
- return (layer != g_instance_layers.cend()) ? &*layer : nullptr;
+ return FindLayer(name);
}
const Layer* FindDeviceLayer(const char* name) {
@@ -368,6 +363,15 @@
return g_instance_layers[index];
}
+const Layer* FindLayer(const char* name) {
+ auto layer =
+ std::find_if(g_instance_layers.cbegin(), g_instance_layers.cend(),
+ [=](const Layer& entry) {
+ return strcmp(entry.properties.layerName, name) == 0;
+ });
+ return (layer != g_instance_layers.cend()) ? &*layer : nullptr;
+}
+
const VkLayerProperties& GetLayerProperties(const Layer& layer) {
return layer.properties;
}
@@ -376,30 +380,16 @@
return layer.is_global;
}
-void GetInstanceLayerExtensions(const char* name,
- const VkExtensionProperties** properties,
- uint32_t* count) {
- const Layer* layer = FindInstanceLayer(name);
- if (layer) {
- *properties = layer->instance_extensions.data();
- *count = static_cast<uint32_t>(layer->instance_extensions.size());
- } else {
- *properties = nullptr;
- *count = 0;
- }
+const VkExtensionProperties* GetLayerInstanceExtensions(const Layer& layer,
+ uint32_t& count) {
+ count = static_cast<uint32_t>(layer.instance_extensions.size());
+ return layer.instance_extensions.data();
}
-void GetDeviceLayerExtensions(const char* name,
- const VkExtensionProperties** properties,
- uint32_t* count) {
- const Layer* layer = FindDeviceLayer(name);
- if (layer) {
- *properties = layer->device_extensions.data();
- *count = static_cast<uint32_t>(layer->device_extensions.size());
- } else {
- *properties = nullptr;
- *count = 0;
- }
+const VkExtensionProperties* GetLayerDeviceExtensions(const Layer& layer,
+ uint32_t& count) {
+ count = static_cast<uint32_t>(layer.device_extensions.size());
+ return layer.device_extensions.data();
}
LayerRef GetInstanceLayerRef(const char* name) {
diff --git a/vulkan/libvulkan/layers_extensions.h b/vulkan/libvulkan/layers_extensions.h
index ee85f00..899d600 100644
--- a/vulkan/libvulkan/layers_extensions.h
+++ b/vulkan/libvulkan/layers_extensions.h
@@ -52,16 +52,15 @@
uint32_t GetLayerCount();
const Layer& GetLayer(uint32_t index);
+const Layer* FindLayer(const char* name);
const VkLayerProperties& GetLayerProperties(const Layer& layer);
bool IsLayerGlobal(const Layer& layer);
+const VkExtensionProperties* GetLayerInstanceExtensions(const Layer& layer,
+ uint32_t& count);
+const VkExtensionProperties* GetLayerDeviceExtensions(const Layer& layer,
+ uint32_t& count);
-void GetInstanceLayerExtensions(const char* name,
- const VkExtensionProperties** properties,
- uint32_t* count);
-void GetDeviceLayerExtensions(const char* name,
- const VkExtensionProperties** properties,
- uint32_t* count);
LayerRef GetInstanceLayerRef(const char* name);
LayerRef GetDeviceLayerRef(const char* name);