void loader_log(const struct loader_instance *inst, VkFlags msg_type,
int32_t msg_code, const char *format, ...) {
char msg[512];
+ char cmd_line_msg[512];
+ uint16_t cmd_line_size = sizeof(cmd_line_msg);
va_list ap;
int ret;
return;
}
+ cmd_line_msg[0] = '\0';
+
+ va_start(ap, format);
+ if ((msg_type & LOADER_INFO_BIT) != 0) {
+ strcat(cmd_line_msg, "INFO");
+ cmd_line_size -= 4;
+ }
+ if ((msg_type & LOADER_WARN_BIT) != 0) {
+ if (cmd_line_size != sizeof(cmd_line_msg)) {
+ strcat(cmd_line_msg, " | ");
+ cmd_line_size -= 3;
+ }
+ strcat(cmd_line_msg, "WARNING");
+ cmd_line_size -= 7;
+ }
+ if ((msg_type & LOADER_PERF_BIT) != 0) {
+ if (cmd_line_size != sizeof(cmd_line_msg)) {
+ strcat(cmd_line_msg, " | ");
+ cmd_line_size -= 3;
+ }
+ strcat(cmd_line_msg, "PERF");
+ cmd_line_size -= 4;
+ }
+ if ((msg_type & LOADER_ERROR_BIT) != 0) {
+ if (cmd_line_size != sizeof(cmd_line_msg)) {
+ strcat(cmd_line_msg, " | ");
+ cmd_line_size -= 3;
+ }
+ strcat(cmd_line_msg, "ERROR");
+ cmd_line_size -= 5;
+ }
+ if ((msg_type & LOADER_DEBUG_BIT) != 0) {
+ if (cmd_line_size != sizeof(cmd_line_msg)) {
+ strcat(cmd_line_msg, " | ");
+ cmd_line_size -= 3;
+ }
+ strcat(cmd_line_msg, "DEBUG");
+ cmd_line_size -= 5;
+ }
+ if (cmd_line_size != sizeof(cmd_line_msg)) {
+ strcat(cmd_line_msg, ": ");
+ cmd_line_size -= 2;
+ }
+ strncat(cmd_line_msg, msg, cmd_line_size);
+
#if defined(WIN32)
- OutputDebugString(msg);
+ OutputDebugString(cmd_line_msg);
OutputDebugString("\n");
#endif
- fputs(msg, stderr);
+ fputs(cmd_line_msg, stderr);
fputc('\n', stderr);
}
#if defined(WIN32)
static char *loader_get_next_path(char *path);
-/**
-* Find the list of registry files (names within a key) in key "location".
-*
-* This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as
-*given in "location"
-* for a list or name/values which are added to a returned list (function return
-*value).
-* The DWORD values within the key must be 0 or they are skipped.
-* Function return is a string with a ';' separated list of filenames.
-* Function return is NULL if no valid name/value pairs are found in the key,
-* or the key is not found.
-*
-* \returns
-* A string list of filenames as pointer.
-* When done using the returned string list, pointer should be freed.
-*/
-static char *loader_get_registry_files(const struct loader_instance *inst,
- char *location) {
+
+// Find the list of registry files (names within a key) in key "location".
+//
+// This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as
+// given in "location"
+// for a list or name/values which are added to a returned list (function return
+// value).
+// The DWORD values within the key must be 0 or they are skipped.
+// Function return is a string with a ';' separated list of filenames.
+// Function return is NULL if no valid name/value pairs are found in the key,
+// or the key is not found.
+//
+// *reg_data contains a string list of filenames as pointer.
+// When done using the returned string list, the caller should free the pointer.
+VkResult loaderGetRegistryFiles(const struct loader_instance *inst,
+ char *location, char **reg_data) {
LONG rtn_value;
HKEY hive, key;
DWORD access_flags;
char name[2048];
- char *out = NULL;
char *loc = location;
char *next;
DWORD idx = 0;
DWORD value;
DWORD total_size = 4096;
DWORD value_size = sizeof(value);
+ VkResult result = VK_SUCCESS;
+ bool found = false;
+
+ if (NULL == reg_data) {
+ result = VK_ERROR_INITIALIZATION_FAILED;
+ goto out;
+ }
while (*loc) {
next = loader_get_next_path(loc);
hive = DEFAULT_VK_REGISTRY_HIVE;
access_flags = KEY_QUERY_VALUE;
rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key);
- if (rtn_value != ERROR_SUCCESS) {
+ if (ERROR_SUCCESS != rtn_value) {
// We still couldn't find the key, so give up:
loc = next;
continue;
NULL, (LPBYTE)&value, &value_size)) ==
ERROR_SUCCESS) {
if (value_size == sizeof(value) && value == 0) {
- if (out == NULL) {
- out = loader_instance_heap_alloc(
+ if (NULL == *reg_data) {
+ *reg_data = loader_instance_heap_alloc(
inst, total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- if (NULL == out) {
+ if (NULL == *reg_data) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
- "Out of memory can't alloc space for "
- "registry data");
- return NULL;
+ "loaderGetRegistryFiles: Failed to allocate "
+ "space for registry data for key %s",
+ name);
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;
+ goto out;
}
- out[0] = '\0';
- } else if (strlen(out) + name_size + 1 > total_size) {
- out = loader_instance_heap_realloc(
- inst, out, total_size, total_size * 2,
+ *reg_data[0] = '\0';
+ } else if (strlen(*reg_data) + name_size + 1 > total_size) {
+ *reg_data = loader_instance_heap_realloc(
+ inst, *reg_data, total_size, total_size * 2,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- if (NULL == out) {
- loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
- "Out of memory can't realloc space for "
- "registry data");
- return NULL;
+ if (NULL == *reg_data) {
+ loader_log(
+ inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
+ "loaderGetRegistryFiles: Failed to reallocate "
+ "space for registry value of size %d for key %s",
+ total_size * 2, name);
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;
+ goto out;
}
total_size *= 2;
}
- if (strlen(out) == 0)
- snprintf(out, name_size + 1, "%s", name);
- else
- snprintf(out + strlen(out), name_size + 2, "%c%s",
- PATH_SEPARATOR, name);
+ if (strlen(*reg_data) == 0) {
+ snprintf(*reg_data, name_size + 1, "%s", name);
+ } else {
+ snprintf(*reg_data + strlen(*reg_data), name_size + 2,
+ "%c%s", PATH_SEPARATOR, name);
+ }
+ found = true;
}
name_size = 2048;
}
loc = next;
}
- return out;
+ if (!found) {
+ result = VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+out:
+
+ return result;
}
#endif // WIN32
if (NULL == fp_get_proc_addr) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_scanned_icd_add: Attempt to retreive either "
- " \'vkGetInstanceProcAddr\' or "
+ "\'vkGetInstanceProcAddr\' or "
"\'vk_icdGetInstanceProcAddr\' from ICD %s failed.",
filename);
goto out;
if (json_buf == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_json: Failed to allocate space for "
- " JSON file %s buffer of length %d",
+ "JSON file %s buffer of length %d",
filename, len);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (*json == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_json: Failed to parse JSON file %s, "
- " this is usually because something ran out of "
- " memory.",
+ "this is usually because something ran out of "
+ "memory.",
filename);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (NULL == dst->instance_extension_list.list) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_copy_layer_properties: Failed to allocate space "
- " for instance extension list of size %d.",
+ "for instance extension list of size %d.",
src->instance_extension_list.count);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
if (NULL == dst->device_extension_list.list) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_copy_layer_properties: Failed to allocate space "
- " for device extension list of size %d.",
+ "for device extension list of size %d.",
src->device_extension_list.count);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
if (NULL == dst->device_extension_list.list->entrypoints) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_copy_layer_properties: Failed to allocate space "
- " for device extension entrypoint list of size %d.",
+ "for device extension entrypoint list of size %d.",
cnt);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) {
loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
"loader_add_layer_properties: Unexpected manifest file "
- " version (expected 1.0.0 or 1.0.1) in %s, may cause "
+ "version (expected 1.0.0 or 1.0.1) in %s, may cause "
"errors",
filename);
}
if (file_major_vers == 1 && file_minor_vers == 0 &&
file_patch_vers == 0) {
loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
- "loader_add_layer_properties: \"layers\" tag not "
+ "loader_add_layer_properties: \'layers\' tag not "
"supported until file version 1.0.1, but %s is "
"reporting version %s",
filename, file_vers);
if (layer_node == NULL) {
loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
"loader_add_layer_properties: Can not find "
- "\"layers\" array element %d object in manifest "
+ "\'layers\' array element %d object in manifest "
"JSON file %s. Skipping this file",
curLayer, filename);
return;
layer_node = cJSON_GetObjectItem(json, "layer");
if (layer_node == NULL) {
loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
- "loader_add_layer_properties: Can not find \"layer\" "
+ "loader_add_layer_properties: Can not find \'layer\' "
"object in manifest JSON file %s. Skipping this file.",
filename);
return;
(file_major_vers > 1 ||
!(file_minor_vers == 0 && file_patch_vers == 0))) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
- "loader_add_layer_properties: Multiple \"layer\" nodes"
+ "loader_add_layer_properties: Multiple \'layer\' nodes"
" are deprecated starting in file version \"1.0.1\". "
- "Please use \"layers\" : [] array instead in %s.",
+ "Please use \'layers\' : [] array instead in %s.",
filename);
} else {
do {
if (loc == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate "
- " %d bytes for manifest file location.",
+ "%d bytes for manifest file location.",
strlen(location));
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
strcpy(loc, location);
#if defined(_WIN32)
- reg = loader_get_registry_files(inst, loc);
- if (reg == NULL) {
+ VkResult reg_result = loaderGetRegistryFiles(inst, loc, ®);
+ if (VK_SUCCESS != reg_result || NULL == reg) {
if (!is_layer) {
- loader_log(
- inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
- "loader_get_manifest_files: Registry lookup failed "
- " to get ICD manifest files. Possibly missing Vulkan"
- " driver?");
- // This typically only fails when out of memory, which is
- // critical
- // if this is for the loader.
- res = VK_ERROR_OUT_OF_HOST_MEMORY;
+ loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
+ "loader_get_manifest_files: Registry lookup failed "
+ "to get ICD manifest files. Possibly missing Vulkan"
+ " driver?");
+ if (VK_SUCCESS == reg_result ||
+ VK_ERROR_OUT_OF_HOST_MEMORY == reg_result) {
+ res = reg_result;
+ } else {
+ res = VK_ERROR_INCOMPATIBLE_DRIVER;
+ }
} else {
if (warn_if_not_present) {
- // warning only for layers
+ // This is only a warning for layers
loader_log(
inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
"loader_get_manifest_files: Registry lookup failed "
- " to get layer manifest files.");
+ "to get layer manifest files.");
+ }
+ if (reg_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
+ res = reg_result;
+ } else {
+ // Return success for now since it's not critical for layers
+ res = VK_SUCCESS;
}
- // Return success for now since it's not critical for layers
- res = VK_SUCCESS;
}
goto out;
}
loader_log(
inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate space for "
- " override environment variable of length %d",
+ "override environment variable of length %d",
strlen(override) + 1);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (dir == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate "
- " space for relative location path length %d",
+ "space for relative location path length %d",
strlen(loc) + 1);
goto out;
}
if (out_files->filename_list == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate "
- " space for manifest file name list");
+ "space for manifest file name list");
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
if (out_files->filename_list[out_files->count] == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate "
- " space for manifest file %d list",
+ "space for manifest file %d list",
out_files->count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (home_loc == NULL) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate "
- " space for manifest file XDG Home location");
+ "space for manifest file XDG Home location");
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
loader_log(
inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_get_manifest_files: Failed to allocate "
- " space for manifest file Home location");
+ "space for manifest file Home location");
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_icd_scan: Failed to allocate space for "
"ICD JSON %s \'library_path\' value. Skipping "
- " ICD JSON.",
+ "ICD JSON.",
file_str);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
cJSON_Free(temp);
"loader_icd_scan: Failed to add ICD JSON %s. "
" Skipping ICD JSON.",
fullpath);
- cJSON_Free(temp);
- cJSON_Delete(json);
- json = NULL;
continue;
}
num_good_icds++;
if (result != VK_STRING_ERROR_NONE) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"loader_validate_layers: Device ppEnabledLayerNames "
- " contains string that is too long or is badly formed");
+ "contains string that is too long or is badly formed");
return VK_ERROR_LAYER_NOT_PRESENT;
}
icd_term = loader_icd_add(
ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]);
if (NULL == icd_term) {
- loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT,
0,
"terminator_CreateInstance: Failed to add ICD %d to ICD "
"trampoline list.",
if (NULL == new_phys_devs) {
loader_log(
inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
- "setupLoaderTrampPhysDevs: Failed to allocate new physical device "
- "array of size %d",
+ "setupLoaderTrampPhysDevs: Failed to allocate new physical device"
+ " array of size %d",
total_count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (NULL == icd_phys_dev_array) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"setupLoaderTermPhysDevs: Failed to allocate temporary "
- " ICD Physical device info array of size %d",
+ "ICD Physical device info array of size %d",
inst->total_gpu_count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (NULL == icd_phys_dev_array[i].phys_devs) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"setupLoaderTermPhysDevs: Failed to allocate temporary "
- " ICD Physical device array for ICD %d of size %d",
+ "ICD Physical device array for ICD %d of size %d",
i, inst->total_gpu_count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;