VkDebugUtilsMessengerEXT用法的最小Vulkan示例不输出任何内容?

时间:2019-01-26 04:03:43

标签: vulkan

以下Vulkan程序尝试创建实例并设置VkDebugUtilsMessengerEXT-但运行时不会输出任何内容:

#include <stdlib.h>
#include <stdio.h>
#include <vulkan/vulkan.h>

VkBool32 VKAPI_PTR debug_utils_messenger_callback(
    VkDebugUtilsMessageSeverityFlagBitsEXT           messageSeverity,
    VkDebugUtilsMessageTypeFlagsEXT                  messageType,
    const VkDebugUtilsMessengerCallbackDataEXT*      pCallbackData,
    void*                                            pUserData) {
  printf("%s", pCallbackData->pMessage);
  return VK_FALSE;
}

int main() {
  // create instance
  VkInstanceCreateInfo instance_create_info = {};
  instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
  const char* layers[] = {"VK_LAYER_LUNARG_standard_validation"};
  instance_create_info.ppEnabledLayerNames = layers;
  instance_create_info.enabledLayerCount = 1;
  const char* extensions[] = {VK_EXT_DEBUG_UTILS_EXTENSION_NAME};
  instance_create_info.enabledExtensionCount = 1;
  instance_create_info.ppEnabledExtensionNames = extensions;
  VkInstance instance;
  if (VK_SUCCESS != vkCreateInstance(&instance_create_info, NULL, &instance))
    exit(EXIT_FAILURE);

  // load kCreateDebugUtilsMessengerEXT
  PFN_vkCreateDebugUtilsMessengerEXT pvkCreateDebugUtilsMessengerEXT =
     (PFN_vkCreateDebugUtilsMessengerEXT)
     vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
  if (pvkCreateDebugUtilsMessengerEXT == NULL)
    exit(EXIT_FAILURE);

  // create debug utils messenger
  VkDebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info = {};
  debug_utils_messenger_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
  debug_utils_messenger_create_info.messageSeverity =
      VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
      VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
      VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
      VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
  debug_utils_messenger_create_info.messageType =
      VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
      VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT |
      VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
  debug_utils_messenger_create_info.pfnUserCallback = debug_utils_messenger_callback;
  VkDebugUtilsMessengerEXT debug_utils_messenger;
  if (VK_SUCCESS != pvkCreateDebugUtilsMessengerEXT(instance, &debug_utils_messenger_create_info, NULL, &debug_utils_messenger))
    exit(EXIT_FAILURE);

  // destroy instance
  vkDestroyInstance(instance, NULL);
}

为什么不呢?我希望它会从debug_utils_messenger_callback输出一些调试消息?

1 个答案:

答案 0 :(得分:1)

Object Tracker确实跟踪调试实用程序对象,但是看起来该层仅在DestroyInstance-time上报告属于未销毁设备对象的对象,并且debugutils显示在该列表中。它应该放在单独的Instance对象列表中,并在DestroyInstance时吐出。

已提交github问题:https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/658