Skip to content

Commit 5be72bb

Browse files
loader: Log VkInstanceCreateInfo for debugging
vkCreateInstance now logs the application's VkApplicationInfo (app and engine name and version, apiVersion) plus the requested instance layers and extensions at info level, so they show up under VK_LOADER_DEBUG. This helps when debugging instance setup and when matching driver workarounds to a specific application. Closes #1819
1 parent 792ddba commit 5be72bb

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

loader/trampoline.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,41 @@ void loader_remove_instance_only_debug_funcs(struct loader_instance *ptr_instanc
478478
}
479479
}
480480

481+
// Dump the app's VkInstanceCreateInfo under VK_LOADER_DEBUG (names, versions, requested layers/extensions). Handy
482+
// for debugging instance setup and matching driver workarounds to a specific app.
483+
static void loader_log_instance_create_info(const struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo) {
484+
const VkApplicationInfo *app_info = pCreateInfo->pApplicationInfo;
485+
const char *app_name = (app_info && app_info->pApplicationName) ? app_info->pApplicationName : "";
486+
const char *engine_name = (app_info && app_info->pEngineName) ? app_info->pEngineName : "";
487+
uint32_t app_version = app_info ? app_info->applicationVersion : 0;
488+
uint32_t engine_version = app_info ? app_info->engineVersion : 0;
489+
uint32_t api_version = app_info ? app_info->apiVersion : 0;
490+
491+
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
492+
"vkCreateInstance: applicationName: \"%s\", applicationVersion: %u, engineName: \"%s\", engineVersion: %u, "
493+
"apiVersion: %u.%u.%u",
494+
app_name, app_version, engine_name, engine_version, VK_API_VERSION_MAJOR(api_version),
495+
VK_API_VERSION_MINOR(api_version), VK_API_VERSION_PATCH(api_version));
496+
497+
// Guard the name arrays: this runs before the loader validates pCreateInfo, so the count may be non-zero with a null
498+
// array (see the null-pointer tests).
499+
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
500+
"vkCreateInstance: Requested %u instance layer(s):", pCreateInfo->enabledLayerCount);
501+
if (pCreateInfo->ppEnabledLayerNames) {
502+
for (uint32_t i = 0; i < pCreateInfo->enabledLayerCount; ++i) {
503+
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, " %s", pCreateInfo->ppEnabledLayerNames[i]);
504+
}
505+
}
506+
507+
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
508+
"vkCreateInstance: Requested %u instance extension(s):", pCreateInfo->enabledExtensionCount);
509+
if (pCreateInfo->ppEnabledExtensionNames) {
510+
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i) {
511+
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, " %s", pCreateInfo->ppEnabledExtensionNames[i]);
512+
}
513+
}
514+
}
515+
481516
LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
482517
const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) {
483518
struct loader_instance *ptr_instance = NULL;
@@ -543,6 +578,8 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
543578
goto out;
544579
}
545580

581+
loader_log_instance_create_info(ptr_instance, pCreateInfo);
582+
546583
VkResult settings_file_res = get_loader_settings(ptr_instance, &ptr_instance->settings);
547584
if (settings_file_res == VK_ERROR_OUT_OF_HOST_MEMORY) {
548585
res = settings_file_res;

tests/loader_regression_tests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ TEST(CreateInstance, ApiVersionBelow1_0) {
142142
"greater than or equal to the value of VK_API_VERSION_1_0 [VUID-VkApplicationInfo-apiVersion]"));
143143
}
144144

145+
// The loader should log the application's VkInstanceCreateInfo so it shows up under VK_LOADER_DEBUG. See #1819.
146+
TEST(CreateInstance, LogsInstanceCreateInfo) {
147+
FrameworkEnvironment env{};
148+
env.add_icd(TEST_ICD_PATH_VERSION_2);
149+
150+
DebugUtilsLogger debug_log{VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
151+
InstWrapper inst{env.vulkan_functions};
152+
inst.create_info.set_app_name("MyTestApp")
153+
.set_app_version(42)
154+
.set_engine_name("MyTestEngine")
155+
.set_engine_version(7)
156+
.set_api_version(1, 2, 0);
157+
FillDebugUtilsCreateDetails(inst.create_info, debug_log);
158+
inst.CheckCreate();
159+
160+
ASSERT_TRUE(debug_log.find("applicationName: \"MyTestApp\", applicationVersion: 42"));
161+
ASSERT_TRUE(debug_log.find("engineName: \"MyTestEngine\", engineVersion: 7, apiVersion: 1.2.0"));
162+
// FillDebugUtilsCreateDetails enables VK_EXT_debug_utils, so it should appear in the requested-extensions dump.
163+
ASSERT_TRUE(debug_log.find("VK_EXT_debug_utils"));
164+
}
165+
145166
TEST(CreateInstance, ConsecutiveCreate) {
146167
FrameworkEnvironment env{};
147168
env.add_icd(TEST_ICD_PATH_VERSION_2);

0 commit comments

Comments
 (0)