Use VK_EXT_debug_utils instead of deprecated VK_EXT_debug_report. (#389)

This commit is contained in:
Andreas Süßenbach 2019-09-25 11:56:46 +02:00 committed by Markus Tavenrath
parent 48d540a23d
commit 9df0fac638
40 changed files with 294 additions and 249 deletions

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -33,7 +33,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -30,7 +30,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -29,7 +29,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -56,7 +56,7 @@ int main(int /*argc*/, char ** /*argv*/)
// Create the instance // Create the instance
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
// Get the list of physical devices // Get the list of physical devices

View File

@ -27,7 +27,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -1,129 +0,0 @@
// Copyright(c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// VulkanHpp Samples : CreateDebugReportCallback
// Draw a cube
#include "vulkan/vulkan.hpp"
#include <iostream>
#include <sstream>
static char const* AppName = "CreateDebugReportCallback";
static char const* EngineName = "Vulkan.hpp";
PFN_vkCreateDebugReportCallbackEXT pfnVkCreateDebugReportCallbackEXT;
PFN_vkDestroyDebugReportCallbackEXT pfnVkDestroyDebugReportCallbackEXT;
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback)
{
return pfnVkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
}
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator)
{
pfnVkDestroyDebugReportCallbackEXT(instance, callback, pAllocator);
}
VKAPI_ATTR VkBool32 VKAPI_CALL dbgFunc(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT /*objType*/, uint64_t /*srcObject*/, size_t /*location*/, int32_t msgCode, const char *pLayerPrefix, const char *pMsg, void * /*pUserData*/)
{
std::ostringstream message;
switch (flags)
{
case VK_DEBUG_REPORT_INFORMATION_BIT_EXT:
message << "INFORMATION: ";
break;
case VK_DEBUG_REPORT_WARNING_BIT_EXT:
message << "WARNING: ";
break;
case VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT:
message << "PERFORMANCE WARNING: ";
break;
case VK_DEBUG_REPORT_ERROR_BIT_EXT:
message << "ERROR: ";
break;
case VK_DEBUG_REPORT_DEBUG_BIT_EXT:
message << "DEBUG: ";
break;
default:
message << "unknown flag (" << flags << "): ";
break;
}
message << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg;
#ifdef _WIN32
MessageBox(NULL, message.str().c_str(), "Alert", MB_OK);
#else
std::cout << message.str() << std::endl;
#endif
return false;
}
int main(int /*argc*/, char ** /*argv*/)
{
try
{
/* VULKAN_KEY_START */
std::vector<vk::ExtensionProperties> props = vk::enumerateInstanceExtensionProperties();
auto propsIterator = std::find_if(props.begin(), props.end(), [](vk::ExtensionProperties const& ep) { return strcmp(ep.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0; });
if (propsIterator == props.end())
{
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_REPORT_EXTENSION_NAME << " extension" << std::endl;
exit(1);
}
vk::ApplicationInfo applicationInfo(AppName, 1, EngineName, 1, VK_API_VERSION_1_0);
const char *extensionName = VK_EXT_DEBUG_REPORT_EXTENSION_NAME;
vk::UniqueInstance instance = vk::createInstanceUnique(vk::InstanceCreateInfo(vk::InstanceCreateFlags(), &applicationInfo, 0, nullptr, 1, &extensionName));
pfnVkCreateDebugReportCallbackEXT = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(instance->getProcAddr("vkCreateDebugReportCallbackEXT"));
if (!pfnVkCreateDebugReportCallbackEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find vkCreateDebugReportCallbackEXT function." << std::endl;
exit(1);
}
pfnVkDestroyDebugReportCallbackEXT = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(instance->getProcAddr("vkDestroyDebugReportCallbackEXT"));
if (!pfnVkDestroyDebugReportCallbackEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find vkDestroyDebugReportCallbackEXT function." << std::endl;
exit(1);
}
vk::UniqueDebugReportCallbackEXT debugReportCallback = instance->createDebugReportCallbackEXTUnique(vk::DebugReportCallbackCreateInfoEXT(vk::DebugReportFlagBitsEXT::eError | vk::DebugReportFlagBitsEXT::eWarning, dbgFunc));
/* VULKAN_KEY_END */
}
catch (vk::SystemError err)
{
std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1);
}
catch (std::runtime_error err)
{
std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1);
}
catch (...)
{
std::cout << "unknown error\n";
exit(-1);
}
return 0;
}

View File

@ -14,22 +14,22 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.2)
project(CreateDebugReportCallback) project(CreateDebugUtilsMessenger)
set(HEADERS set(HEADERS
) )
set(SOURCES set(SOURCES
CreateDebugReportCallback.cpp CreateDebugUtilsMessenger.cpp
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES}) source_group(sources FILES ${SOURCES})
add_executable(CreateDebugReportCallback add_executable(CreateDebugUtilsMessenger
${HEADERS} ${HEADERS}
${SOURCES} ${SOURCES}
) )
set_target_properties(CreateDebugReportCallback PROPERTIES FOLDER "Samples") set_target_properties(CreateDebugUtilsMessenger PROPERTIES FOLDER "Samples")
target_link_libraries(CreateDebugReportCallback PUBLIC "${Vulkan_LIBRARIES}") target_link_libraries(CreateDebugUtilsMessenger PUBLIC "${Vulkan_LIBRARIES}")

View File

@ -0,0 +1,144 @@
// Copyright(c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// VulkanHpp Samples : CreateDebugReportMessenger
// Draw a cube
#include "vulkan/vulkan.hpp"
#include <iostream>
#include <sstream>
static char const* AppName = "CreateDebugReportMessenger";
static char const* EngineName = "Vulkan.hpp";
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
{
return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
}
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
{
return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
}
VkBool32 debugMessageFunc(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/)
{
std::ostringstream message;
message << vk::to_string(static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) << ": " << vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(messageTypes)) << ":\n";
message << "\t" << "messageIDName = <" << pCallbackData->pMessageIdName << ">\n";
message << "\t" << "messageIdNumber = " << pCallbackData->messageIdNumber << "\n";
message << "\t" << "message = <" << pCallbackData->pMessage << ">\n";
if (0 < pCallbackData->queueLabelCount)
{
message << "\t" << "Queue Labels:\n";
for (uint8_t i = 0; i < pCallbackData->queueLabelCount; i++)
{
message << "\t\t" << "lableName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
}
}
if (0 < pCallbackData->cmdBufLabelCount)
{
message << "\t" << "CommandBuffer Labels:\n";
for (uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++)
{
message << "\t\t" << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
}
}
if (0 < pCallbackData->objectCount)
{
message << "\t" << "Objects:\n";
for (uint8_t i = 0; i < pCallbackData->objectCount; i++)
{
message << "\t\t" << "Object " << i << "\n";
message << "\t\t\t" << "objectType = " << vk::to_string(static_cast<vk::ObjectType>(pCallbackData->pObjects[i].objectType)) << "\n";
message << "\t\t\t" << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if (pCallbackData->pObjects[i].pObjectName)
{
message << "\t\t\t" << "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
}
}
}
#ifdef _WIN32
MessageBox(NULL, message.str().c_str(), "Alert", MB_OK);
#else
std::cout << message.str() << std::endl;
#endif
return false;
}
int main(int /*argc*/, char ** /*argv*/)
{
try
{
/* VULKAN_KEY_START */
std::vector<vk::ExtensionProperties> props = vk::enumerateInstanceExtensionProperties();
auto propsIterator = std::find_if(props.begin(), props.end(), [](vk::ExtensionProperties const& ep) { return strcmp(ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; });
if (propsIterator == props.end())
{
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" << std::endl;
exit(1);
}
vk::ApplicationInfo applicationInfo(AppName, 1, EngineName, 1, VK_API_VERSION_1_1);
const char *extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
vk::UniqueInstance instance = vk::createInstanceUnique(vk::InstanceCreateInfo(vk::InstanceCreateFlags(), &applicationInfo, 0, nullptr, 1, &extensionName));
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
if (!pfnVkCreateDebugUtilsMessengerEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit(1);
}
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT"));
if (!pfnVkDestroyDebugUtilsMessengerEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
exit(1);
}
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags(vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError);
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags(vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation);
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = instance->createDebugUtilsMessengerEXTUnique(vk::DebugUtilsMessengerCreateInfoEXT({}, severityFlags, messageTypeFlags, &debugMessageFunc));
/* VULKAN_KEY_END */
}
catch (vk::SystemError err)
{
std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1);
}
catch (std::runtime_error err)
{
std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1);
}
catch (...)
{
std::cout << "unknown error\n";
exit(-1);
}
return 0;
}

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -24,46 +24,59 @@
static char const* AppName = "EnableValidationWithCallback"; static char const* AppName = "EnableValidationWithCallback";
static char const* EngineName = "Vulkan.hpp"; static char const* EngineName = "Vulkan.hpp";
PFN_vkCreateDebugReportCallbackEXT pfnVkCreateDebugReportCallbackEXT; PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugReportCallbackEXT pfnVkDestroyDebugReportCallbackEXT; PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
{ {
return pfnVkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback); return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator) VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
{ {
pfnVkDestroyDebugReportCallbackEXT(instance, callback, pAllocator); return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
} }
VKAPI_ATTR VkBool32 VKAPI_CALL dbgFunc(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT /*objType*/, uint64_t /*srcObject*/, size_t /*location*/, int32_t msgCode, const char *pLayerPrefix, const char *pMsg, void * /*pUserData*/) VkBool32 debugMessageFunc(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/)
{ {
std::ostringstream message; std::ostringstream message;
switch (flags) message << vk::to_string(static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) << ": " << vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(messageTypes)) << ":\n";
message << "\t" << "messageIDName = <" << pCallbackData->pMessageIdName << ">\n";
message << "\t" << "messageIdNumber = " << pCallbackData->messageIdNumber << "\n";
message << "\t" << "message = <" << pCallbackData->pMessage << ">\n";
if (0 < pCallbackData->queueLabelCount)
{ {
case VK_DEBUG_REPORT_INFORMATION_BIT_EXT: message << "\t" << "Queue Labels:\n";
message << "INFORMATION: "; for (uint8_t i = 0; i < pCallbackData->queueLabelCount; i++)
break; {
case VK_DEBUG_REPORT_WARNING_BIT_EXT: message << "\t\t" << "lableName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
message << "WARNING: ";
break;
case VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT:
message << "PERFORMANCE WARNING: ";
break;
case VK_DEBUG_REPORT_ERROR_BIT_EXT:
message << "ERROR: ";
break;
case VK_DEBUG_REPORT_DEBUG_BIT_EXT:
message << "DEBUG: ";
break;
default:
message << "unknown flag (" << flags << "): ";
break;
} }
message << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg; }
if (0 < pCallbackData->cmdBufLabelCount)
{
message << "\t" << "CommandBuffer Labels:\n";
for (uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++)
{
message << "\t\t" << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
}
}
if (0 < pCallbackData->objectCount)
{
message << "\t" << "Objects:\n";
for (uint8_t i = 0; i < pCallbackData->objectCount; i++)
{
message << "\t\t" << "Object " << i << "\n";
message << "\t\t\t" << "objectType = " << vk::to_string(static_cast<vk::ObjectType>(pCallbackData->pObjects[i].objectType)) << "\n";
message << "\t\t\t" << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if (pCallbackData->pObjects[i].pObjectName)
{
message << "\t\t\t" << "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
}
}
}
#ifdef _WIN32 #ifdef _WIN32
MessageBox(NULL, message.str().c_str(), "Alert", MB_OK); MessageBox(NULL, message.str().c_str(), "Alert", MB_OK);
@ -102,13 +115,31 @@ int main(int /*argc*/, char ** /*argv*/)
/* Enable debug callback extension */ /* Enable debug callback extension */
std::vector<char const*> instanceExtensionNames; std::vector<char const*> instanceExtensionNames;
instanceExtensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); instanceExtensionNames.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
vk::ApplicationInfo applicationInfo(AppName, 1, EngineName, 1, VK_API_VERSION_1_0); vk::ApplicationInfo applicationInfo(AppName, 1, EngineName, 1, VK_API_VERSION_1_1);
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, vk::su::checked_cast<uint32_t>(instanceLayerNames.size()), instanceLayerNames.data(), vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, vk::su::checked_cast<uint32_t>(instanceLayerNames.size()), instanceLayerNames.data(),
vk::su::checked_cast<uint32_t>(instanceExtensionNames.size()) , instanceExtensionNames.data() ); vk::su::checked_cast<uint32_t>(instanceExtensionNames.size()) , instanceExtensionNames.data() );
vk::UniqueInstance instance = vk::createInstanceUnique(instanceCreateInfo); vk::UniqueInstance instance = vk::createInstanceUnique(instanceCreateInfo);
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
if (!pfnVkCreateDebugUtilsMessengerEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
exit(1);
}
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT"));
if (!pfnVkDestroyDebugUtilsMessengerEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
exit(1);
}
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags(vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError);
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags(vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation);
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = instance->createDebugUtilsMessengerEXTUnique(vk::DebugUtilsMessengerCreateInfoEXT({}, severityFlags, messageTypeFlags, &debugMessageFunc));
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
@ -122,21 +153,6 @@ int main(int /*argc*/, char ** /*argv*/)
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority); vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority);
vk::UniqueDevice device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo)); vk::UniqueDevice device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo));
pfnVkCreateDebugReportCallbackEXT = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(instance->getProcAddr("vkCreateDebugReportCallbackEXT"));
if (!pfnVkCreateDebugReportCallbackEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find vkCreateDebugReportCallbackEXT function." << std::endl;
exit(1);
}
pfnVkDestroyDebugReportCallbackEXT = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(instance->getProcAddr("vkDestroyDebugReportCallbackEXT"));
if (!pfnVkDestroyDebugReportCallbackEXT)
{
std::cout << "GetInstanceProcAddr: Unable to find vkDestroyDebugReportCallbackEXT function." << std::endl;
exit(1);
}
vk::UniqueDebugReportCallbackEXT debugReportCallback = instance->createDebugReportCallbackEXTUnique(vk::DebugReportCallbackCreateInfoEXT(vk::DebugReportFlagBitsEXT::eError | vk::DebugReportFlagBitsEXT::eWarning, dbgFunc));
// Create a command pool (not a UniqueCommandPool, for testing purposes! // Create a command pool (not a UniqueCommandPool, for testing purposes!
vk::CommandPool commandPool = device->createCommandPool(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlags(), queueFamilyIndex)); vk::CommandPool commandPool = device->createCommandPool(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlags(), queueFamilyIndex));

View File

@ -29,7 +29,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */

View File

@ -28,7 +28,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -60,7 +60,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -82,7 +82,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -64,7 +64,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -31,7 +31,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -73,7 +73,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -45,7 +45,7 @@ int main(int /*argc*/, char ** /*argv*/)
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, instanceExtensions); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, instanceExtensions);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -650,7 +650,7 @@ int main(int /*argc*/, char** /*argv*/)
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, instanceExtensions); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, instanceExtensions);
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReport = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -62,7 +62,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -32,7 +32,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -59,7 +59,7 @@ int main(int /*argc*/, char ** /*argv*/)
{ {
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions()); vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions());
#if !defined(NDEBUG) #if !defined(NDEBUG)
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance); vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
#endif #endif
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front(); vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();

View File

@ -18,17 +18,17 @@
#include <iomanip> #include <iomanip>
#include <numeric> #include <numeric>
PFN_vkCreateDebugReportCallbackEXT pfnVkCreateDebugReportCallbackEXT; PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugReportCallbackEXT pfnVkDestroyDebugReportCallbackEXT; PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
{ {
return pfnVkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback); return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator) VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
{ {
pfnVkDestroyDebugReportCallbackEXT(instance, callback, pAllocator); return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
} }
namespace vk namespace vk
@ -49,10 +49,11 @@ namespace vk
return device->createCommandPoolUnique(commandPoolCreateInfo); return device->createCommandPoolUnique(commandPoolCreateInfo);
} }
vk::UniqueDebugReportCallbackEXT createDebugReportCallback(vk::UniqueInstance &instance) vk::UniqueDebugUtilsMessengerEXT createDebugUtilsMessenger(vk::UniqueInstance &instance)
{ {
vk::DebugReportFlagsEXT flags(vk::DebugReportFlagBitsEXT::eWarning | vk::DebugReportFlagBitsEXT::ePerformanceWarning | vk::DebugReportFlagBitsEXT::eError); vk::DebugUtilsMessageSeverityFlagsEXT severityFlags(vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError);
return instance->createDebugReportCallbackEXTUnique(vk::DebugReportCallbackCreateInfoEXT(flags, &vk::su::debugReportCallback)); vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags(vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation);
return instance->createDebugUtilsMessengerEXTUnique(vk::DebugUtilsMessengerCreateInfoEXT({}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback));
} }
vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes) vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes)
@ -193,9 +194,9 @@ namespace vk
enabledExtensions.push_back(ext.data()); enabledExtensions.push_back(ext.data());
} }
#if !defined(NDEBUG) #if !defined(NDEBUG)
if (std::find(extensions.begin(), extensions.end(), VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == extensions.end()) if (std::find(extensions.begin(), extensions.end(), VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == extensions.end())
{ {
enabledExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); enabledExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
} }
#endif #endif
@ -208,9 +209,9 @@ namespace vk
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)
{ {
pfnVkCreateDebugReportCallbackEXT = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(instance->getProcAddr("vkCreateDebugReportCallbackEXT")); pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
pfnVkDestroyDebugReportCallbackEXT = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(instance->getProcAddr("vkDestroyDebugReportCallbackEXT")); pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT"));
assert(pfnVkCreateDebugReportCallbackEXT && pfnVkDestroyDebugReportCallbackEXT); assert(pfnVkCreateDebugUtilsMessengerEXT && pfnVkDestroyDebugUtilsMessengerEXT);
initialized = true; initialized = true;
} }
#endif #endif
@ -238,30 +239,43 @@ namespace vk
&subpassDescription)); &subpassDescription));
} }
VkBool32 debugReportCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT /*objectType*/, uint64_t /*object*/, size_t /*location*/, int32_t /*messageCode*/, const char* /*pLayerPrefix*/, const char* pMessage, void* /*pUserData*/) VkBool32 debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/)
{ {
switch (flags) std::cerr << vk::to_string(static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) << ": " << vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(messageTypes)) << ":\n";
std::cerr << "\t" << "messageIDName = <" << pCallbackData->pMessageIdName << ">\n";
std::cerr << "\t" << "messageIdNumber = " << pCallbackData->messageIdNumber << "\n";
std::cerr << "\t" << "message = <" << pCallbackData->pMessage << ">\n";
if (0 < pCallbackData->queueLabelCount)
{ {
case VK_DEBUG_REPORT_INFORMATION_BIT_EXT: std::cerr << "\t" << "Queue Labels:\n";
std::cerr << "INFORMATION: "; for (uint8_t i = 0; i < pCallbackData->queueLabelCount; i++)
break; {
case VK_DEBUG_REPORT_WARNING_BIT_EXT: std::cerr << "\t\t" << "lableName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
std::cerr << "WARNING: "; }
break; }
case VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT: if (0 < pCallbackData->cmdBufLabelCount)
std::cerr << "PERFORMANCE WARNING: "; {
break; std::cerr << "\t" << "CommandBuffer Labels:\n";
case VK_DEBUG_REPORT_ERROR_BIT_EXT: for (uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++)
std::cerr << "ERROR: "; {
break; std::cerr << "\t\t" << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
case VK_DEBUG_REPORT_DEBUG_BIT_EXT: }
std::cerr << "DEBUG: "; }
break; if (0 < pCallbackData->objectCount)
default: {
std::cerr << "unknown flag (" << flags << "): "; std::cerr << "\t" << "Objects:\n";
break; for (uint8_t i = 0; i < pCallbackData->objectCount; i++)
{
std::cerr << "\t\t" << "Object " << i << "\n";
std::cerr << "\t\t\t" << "objectType = " << vk::to_string(static_cast<vk::ObjectType>(pCallbackData->pObjects[i].objectType)) << "\n";
std::cerr << "\t\t\t" << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
if (pCallbackData->pObjects[i].pObjectName)
{
std::cerr << "\t\t\t" << "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
}
}
} }
std::cerr << pMessage << std::endl;
return VK_TRUE; return VK_TRUE;
} }

View File

@ -264,7 +264,7 @@ namespace vk
vk::UniqueDeviceMemory allocateMemory(vk::UniqueDevice const& device, vk::PhysicalDeviceMemoryProperties const& memoryProperties, vk::MemoryRequirements const& memoryRequirements, vk::UniqueDeviceMemory allocateMemory(vk::UniqueDevice const& device, vk::PhysicalDeviceMemoryProperties const& memoryProperties, vk::MemoryRequirements const& memoryRequirements,
vk::MemoryPropertyFlags memoryPropertyFlags); vk::MemoryPropertyFlags memoryPropertyFlags);
vk::UniqueCommandPool createCommandPool(vk::UniqueDevice &device, uint32_t queueFamilyIndex); vk::UniqueCommandPool createCommandPool(vk::UniqueDevice &device, uint32_t queueFamilyIndex);
vk::UniqueDebugReportCallbackEXT createDebugReportCallback(vk::UniqueInstance &instance); vk::UniqueDebugUtilsMessengerEXT createDebugUtilsMessenger(vk::UniqueInstance &instance);
vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes); vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes);
vk::UniqueDescriptorSetLayout createDescriptorSetLayout(vk::UniqueDevice const& device, std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const& bindingData, vk::UniqueDescriptorSetLayout createDescriptorSetLayout(vk::UniqueDevice const& device, std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const& bindingData,
vk::DescriptorSetLayoutCreateFlags flags = {}); vk::DescriptorSetLayoutCreateFlags flags = {});
@ -278,7 +278,7 @@ namespace vk
vk::UniqueInstance createInstance(std::string const& appName, std::string const& engineName, std::vector<std::string> const& layers = {}, std::vector<std::string> const& extensions = {}, vk::UniqueInstance createInstance(std::string const& appName, std::string const& engineName, std::vector<std::string> const& layers = {}, std::vector<std::string> const& extensions = {},
uint32_t apiVersion = VK_API_VERSION_1_0); uint32_t apiVersion = VK_API_VERSION_1_0);
vk::UniqueRenderPass createRenderPass(vk::UniqueDevice &device, vk::Format colorFormat, vk::Format depthFormat, vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear, vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR); vk::UniqueRenderPass createRenderPass(vk::UniqueDevice &device, vk::Format colorFormat, vk::Format depthFormat, vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear, vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR);
VkBool32 debugReportCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage, void* pUserData); VkBool32 debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/);
uint32_t findGraphicsQueueFamilyIndex(std::vector<vk::QueueFamilyProperties> const& queueFamilyProperties); uint32_t findGraphicsQueueFamilyIndex(std::vector<vk::QueueFamilyProperties> const& queueFamilyProperties);
std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const& surface); std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const& surface);
uint32_t findMemoryType(vk::PhysicalDeviceMemoryProperties const& memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask); uint32_t findMemoryType(vk::PhysicalDeviceMemoryProperties const& memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask);