diff options
| author | Courtney Goeltzenleuchter <courtneygo@google.com> | 2015-12-03 13:50:49 -0700 |
|---|---|---|
| committer | Jon Ashburn <jon@lunarg.com> | 2015-12-17 11:20:07 -0700 |
| commit | 35f1d09e28ed8773b92eeb6ff7c2ed234f3f2c58 (patch) | |
| tree | 8e852ec727d18d5f6cb56303ed70e370c8dab159 | |
| parent | c1e008de782e3c12eee6ea3a0193be0992bd742c (diff) | |
| download | usermoji-35f1d09e28ed8773b92eeb6ff7c2ed234f3f2c58.tar.xz | |
vulkaninfo: Register a callback at CreateInstance
Add the CreateInstance callback to demonstrate the use of that
limited-time callback mechanism.
| -rw-r--r-- | demos/vulkaninfo.c | 50 |
1 files changed, 50 insertions, 0 deletions
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 <vulkan/vulkan.h> +#include <vulkan/vk_lunarg_debug_report.h> #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"); |
