Introduce usage of clang-format to format vulkan.hpp and the other sources.
This commit is contained in:
@@ -16,68 +16,89 @@
|
||||
// Draw a cube
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
static char const* AppName = "CreateDebugReportMessenger";
|
||||
static char const* EngineName = "Vulkan.hpp";
|
||||
static char const * AppName = "CreateDebugReportMessenger";
|
||||
static char const * EngineName = "Vulkan.hpp";
|
||||
|
||||
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
|
||||
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( VkInstance instance,
|
||||
const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,
|
||||
const VkAllocationCallbacks * pAllocator,
|
||||
VkDebugUtilsMessengerEXT * pMessenger )
|
||||
{
|
||||
return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
|
||||
return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger );
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance,
|
||||
VkDebugUtilsMessengerEXT messenger,
|
||||
VkAllocationCallbacks const * pAllocator )
|
||||
{
|
||||
return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
|
||||
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/)
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL 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 << 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"
|
||||
<< "Queue Labels:\n";
|
||||
for ( uint8_t i = 0; i < pCallbackData->queueLabelCount; i++ )
|
||||
{
|
||||
message << "\t\t" << "labelName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
|
||||
message << "\t\t"
|
||||
<< "labelName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
|
||||
}
|
||||
}
|
||||
if (0 < pCallbackData->cmdBufLabelCount)
|
||||
if ( 0 < pCallbackData->cmdBufLabelCount )
|
||||
{
|
||||
message << "\t" << "CommandBuffer Labels:\n";
|
||||
for (uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++)
|
||||
message << "\t"
|
||||
<< "CommandBuffer Labels:\n";
|
||||
for ( uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++ )
|
||||
{
|
||||
message << "\t\t" << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
|
||||
message << "\t\t"
|
||||
<< "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
|
||||
}
|
||||
}
|
||||
if (0 < pCallbackData->objectCount)
|
||||
if ( 0 < pCallbackData->objectCount )
|
||||
{
|
||||
message << "\t" << "Objects:\n";
|
||||
for (uint8_t i = 0; i < pCallbackData->objectCount; i++)
|
||||
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"
|
||||
<< "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";
|
||||
message << "\t\t\t"
|
||||
<< "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
MessageBox(NULL, message.str().c_str(), "Alert", MB_OK);
|
||||
MessageBox( NULL, message.str().c_str(), "Alert", MB_OK );
|
||||
#else
|
||||
std::cout << message.str() << std::endl;
|
||||
#endif
|
||||
@@ -85,8 +106,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagB
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int main(int /*argc*/, char ** /*argv*/)
|
||||
int main( int /*argc*/, char ** /*argv*/ )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -94,51 +114,61 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
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())
|
||||
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);
|
||||
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));
|
||||
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)
|
||||
pfnVkCreateDebugUtilsMessengerEXT =
|
||||
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance->getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
|
||||
if ( !pfnVkCreateDebugUtilsMessengerEXT )
|
||||
{
|
||||
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
|
||||
exit(1);
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT"));
|
||||
if (!pfnVkDestroyDebugUtilsMessengerEXT)
|
||||
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
|
||||
instance->getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
|
||||
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
|
||||
{
|
||||
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
|
||||
exit(1);
|
||||
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::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)
|
||||
catch ( vk::SystemError & err )
|
||||
{
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
exit(-1);
|
||||
exit( -1 );
|
||||
}
|
||||
catch (std::runtime_error& err)
|
||||
catch ( std::runtime_error & err )
|
||||
{
|
||||
std::cout << "std::runtime_error: " << err.what() << std::endl;
|
||||
exit(-1);
|
||||
exit( -1 );
|
||||
}
|
||||
catch (...)
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "unknown error\n";
|
||||
exit(-1);
|
||||
exit( -1 );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user