loader: Add error return to detect invalid layers
The code already checks that a named layer can be
found on the system, but that result was not being
returned to the caller. That is now plumbed so that
CreateInstance and CreateDevice can return an
VK_ERROR_INVALID_LAYER if a named layer cannot be
found.
diff --git a/loader/loader.c b/loader/loader.c
index 43e344b..0527738 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -673,24 +673,28 @@
* Search the given search_list for any layers in the props list.
* Add these to the output layer_list. Don't add duplicates to the output layer_list.
*/
-static void loader_add_layer_names_to_list(
+static VkResult loader_add_layer_names_to_list(
struct loader_layer_list *output_list,
uint32_t name_count,
const char * const *names,
const struct loader_layer_list *search_list)
{
struct loader_layer_properties *layer_prop;
+ VkResult err = VK_SUCCESS;
for (uint32_t i = 0; i < name_count; i++) {
const char *search_target = names[i];
layer_prop = get_layer_property(search_target, search_list);
if (!layer_prop) {
- loader_log(VK_DBG_REPORT_WARN_BIT, 0, "Unable to find extension %s", search_target);
+ loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Unable to find layer %s", search_target);
+ err = VK_ERROR_INVALID_LAYER;
continue;
}
loader_add_to_layer_list(output_list, 1, layer_prop);
}
+
+ return err;
}
/*
@@ -1970,16 +1974,18 @@
loader_destroy_layer_list(&instance->activated_layer_list);
}
-void loader_enable_instance_layers(
+VkResult loader_enable_instance_layers(
struct loader_instance *inst,
const VkInstanceCreateInfo *pCreateInfo)
{
+ VkResult err;
+
if (inst == NULL)
- return;
+ return VK_ERROR_UNKNOWN;
if (!loader_init_layer_list(&inst->activated_layer_list)) {
loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc Instance activated layer list");
- return;
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
}
/* Add any implicit layers first */
@@ -1995,11 +2001,13 @@
&loader.global_layer_list);
/* Add layers specified by the application */
- loader_add_layer_names_to_list(
+ err = loader_add_layer_names_to_list(
&inst->activated_layer_list,
pCreateInfo->layerCount,
pCreateInfo->ppEnabledLayerNames,
&loader.global_layer_list);
+
+ return err;
}
uint32_t loader_activate_instance_layers(struct loader_instance *inst)
@@ -2087,13 +2095,15 @@
(VkInstance) inst);
}
-static void loader_enable_device_layers(
+static VkResult loader_enable_device_layers(
struct loader_icd *icd,
struct loader_device *dev,
const VkDeviceCreateInfo *pCreateInfo)
{
+ VkResult err;
+
if (dev == NULL)
- return;
+ return VK_ERROR_UNKNOWN;
if (dev->activated_layer_list.list == NULL || dev->activated_layer_list.capacity == 0) {
loader_init_layer_list(&dev->activated_layer_list);
@@ -2101,7 +2111,7 @@
if (dev->activated_layer_list.list == NULL) {
loader_log(VK_DBG_REPORT_ERROR_BIT, 0, "Failed to malloc device activated layer list");
- return;
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
}
/* Add any implicit layers first */
@@ -2117,11 +2127,13 @@
&icd->layer_properties_cache);
/* Add layers specified by the application */
- loader_add_layer_names_to_list(
+ err = loader_add_layer_names_to_list(
&dev->activated_layer_list,
pCreateInfo->layerCount,
pCreateInfo->ppEnabledLayerNames,
&icd->layer_properties_cache);
+
+ return err;
}
/*
@@ -2221,7 +2233,7 @@
struct loader_instance *ptr_instance = *(struct loader_instance **) pInstance;
struct loader_scanned_icds *scanned_icds;
struct loader_icd *icd;
- VkResult res;
+ VkResult res = VK_SUCCESS;
scanned_icds = loader.scanned_icd_list;
while (scanned_icds) {
@@ -2244,11 +2256,20 @@
scanned_icds = scanned_icds->next;
}
+ /*
+ * If no ICDs were added to instance list and res is unchanged
+ * from it's initial value, the loader was unable to find
+ * a suitable ICD.
+ */
if (ptr_instance->icds == NULL) {
- return VK_ERROR_INCOMPATIBLE_DRIVER;
+ if (res == VK_SUCCESS) {
+ return VK_ERROR_INCOMPATIBLE_DRIVER;
+ } else {
+ return res;
+ }
}
- return res;
+ return VK_SUCCESS;
}
VkResult loader_DestroyInstance(
diff --git a/loader/loader.h b/loader/loader.h
index d6ef538..a336238 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -423,7 +423,7 @@
struct loader_icd * loader_get_icd(const VkPhysicalDevice gpu,
uint32_t *gpu_index);
void loader_remove_logical_device(VkDevice device);
-void loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo);
+VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo);
void loader_deactivate_instance_layers(struct loader_instance *instance);
uint32_t loader_activate_instance_layers(struct loader_instance *inst);
void loader_activate_instance_layer_extensions(struct loader_instance *inst);