From 35f1d09e28ed8773b92eeb6ff7c2ed234f3f2c58 Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Thu, 3 Dec 2015 13:50:49 -0700 Subject: vulkaninfo: Register a callback at CreateInstance Add the CreateInstance callback to demonstrate the use of that limited-time callback mechanism. --- demos/vulkaninfo.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/demos/vulkaninfo.c b/demos/vulkaninfo.c index 9af93011..97629eb6 100644 --- a/demos/vulkaninfo.c +++ b/demos/vulkaninfo.c @@ -39,6 +39,7 @@ #include +#include #define ERR(err) printf("%s:%d: failed with %s\n", \ __FILE__, __LINE__, vk_result_string(err)); @@ -128,6 +129,48 @@ struct app_gpu { struct app_dev dev; }; +VkBool32 dbg_callback( + VkFlags msgFlags, + VkDebugReportObjectTypeLUNARG objType, + uint64_t srcObject, + size_t location, + int32_t msgCode, + const char* pLayerPrefix, + const char* pMsg, + const void* pUserData) +{ + char *message = (char *) malloc(strlen(pMsg)+100); + + assert (message); + + if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT) { + sprintf(message,"ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg); + } else if (msgFlags & VK_DEBUG_REPORT_WARN_BIT) { + sprintf(message,"WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg); + } else if (msgFlags & VK_DEBUG_REPORT_INFO_BIT) { + sprintf(message,"INFO: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg); + } else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT) { + sprintf(message,"DEBUG: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg); + } + +#ifdef _WIN32 + MessageBox(NULL, message, "Alert", MB_OK); +#else + printf("%s\n",message); + fflush(stdout); +#endif + free(message); + + /* + * false indicates that layer should not bail-out of an + * API call that had validation failures. This may mean that the + * app dies inside the driver due to invalid parameter(s). + * That's what would happen without validation layers, so we'll + * keep that behavior here. + */ + return false; +} + static const char *vk_result_string(VkResult err) { switch (err) { @@ -644,6 +687,13 @@ static void app_create_instance(struct app_instance *inst) inst_info.enabledExtensionNameCount = global_extension_count; inst_info.ppEnabledExtensionNames = (const char * const *) known_extensions; + VkDebugReportCallbackCreateInfoLUNARG dbg_info; + memset(&dbg_info, 0, sizeof(dbg_info)); + dbg_info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_LUNARG; + dbg_info.flags = VK_DEBUG_REPORT_ERROR_BIT | VK_DEBUG_REPORT_WARN_BIT | VK_DEBUG_REPORT_INFO_BIT; + dbg_info.pfnCallback = dbg_callback; + inst_info.pNext = &dbg_info; + err = vkCreateInstance(&inst_info, NULL, &inst->instance); if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { printf("Cannot create Vulkan instance.\n"); -- cgit v1.2.3