Introduce VULKAN_HPP_NO_TO_STRING to optionally remove the various vk::to_string functions.

Also extend the samples to hold some local version of the needed to_string functions in case VULKAN_HPP_NO_TO_STRING is defined.
This commit is contained in:
asuessenbach
2022-07-25 17:11:30 +02:00
parent 3610b08409
commit 527e52a1bd
24 changed files with 4170 additions and 1570 deletions

View File

@@ -361,6 +361,97 @@ namespace vk
return device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpassDescription ) );
}
#if defined( VULKAN_HPP_NO_TO_STRING )
namespace local
{
std::string to_string( vk::DebugUtilsMessageSeverityFlagBitsEXT value )
{
switch ( value )
{
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose: return "Verbose";
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo: return "Info";
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning: return "Warning";
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError: return "Error";
default: return "invalid ( " + VULKAN_HPP_NAMESPACE::toHexString( static_cast<uint32_t>( value ) ) + " )";
}
}
std::string to_string( vk::DebugUtilsMessageTypeFlagsEXT value )
{
if ( !value )
return "{}";
std::string result;
if ( value & vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral )
result += "General | ";
if ( value & vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation )
result += "Validation | ";
if ( value & vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance )
result += "Performance | ";
return "{ " + result.substr( 0, result.size() - 3 ) + " }";
}
std::string to_string( vk::ObjectType value )
{
switch ( value )
{
case vk::ObjectType::eUnknown: return "Unknown";
case vk::ObjectType::eInstance: return "Instance";
case vk::ObjectType::ePhysicalDevice: return "PhysicalDevice";
case vk::ObjectType::eDevice: return "Device";
case vk::ObjectType::eQueue: return "Queue";
case vk::ObjectType::eSemaphore: return "Semaphore";
case vk::ObjectType::eCommandBuffer: return "CommandBuffer";
case vk::ObjectType::eFence: return "Fence";
case vk::ObjectType::eDeviceMemory: return "DeviceMemory";
case vk::ObjectType::eBuffer: return "Buffer";
case vk::ObjectType::eImage: return "Image";
case vk::ObjectType::eEvent: return "Event";
case vk::ObjectType::eQueryPool: return "QueryPool";
case vk::ObjectType::eBufferView: return "BufferView";
case vk::ObjectType::eImageView: return "ImageView";
case vk::ObjectType::eShaderModule: return "ShaderModule";
case vk::ObjectType::ePipelineCache: return "PipelineCache";
case vk::ObjectType::ePipelineLayout: return "PipelineLayout";
case vk::ObjectType::eRenderPass: return "RenderPass";
case vk::ObjectType::ePipeline: return "Pipeline";
case vk::ObjectType::eDescriptorSetLayout: return "DescriptorSetLayout";
case vk::ObjectType::eSampler: return "Sampler";
case vk::ObjectType::eDescriptorPool: return "DescriptorPool";
case vk::ObjectType::eDescriptorSet: return "DescriptorSet";
case vk::ObjectType::eFramebuffer: return "Framebuffer";
case vk::ObjectType::eCommandPool: return "CommandPool";
case vk::ObjectType::eSamplerYcbcrConversion: return "SamplerYcbcrConversion";
case vk::ObjectType::eDescriptorUpdateTemplate: return "DescriptorUpdateTemplate";
case vk::ObjectType::ePrivateDataSlot: return "PrivateDataSlot";
case vk::ObjectType::eSurfaceKHR: return "SurfaceKHR";
case vk::ObjectType::eSwapchainKHR: return "SwapchainKHR";
case vk::ObjectType::eDisplayKHR: return "DisplayKHR";
case vk::ObjectType::eDisplayModeKHR: return "DisplayModeKHR";
case vk::ObjectType::eDebugReportCallbackEXT: return "DebugReportCallbackEXT";
# if defined( VK_ENABLE_BETA_EXTENSIONS )
case vk::ObjectType::eVideoSessionKHR: return "VideoSessionKHR";
case vk::ObjectType::eVideoSessionParametersKHR: return "VideoSessionParametersKHR";
# endif /*VK_ENABLE_BETA_EXTENSIONS*/
case vk::ObjectType::eCuModuleNVX: return "CuModuleNVX";
case vk::ObjectType::eCuFunctionNVX: return "CuFunctionNVX";
case vk::ObjectType::eDebugUtilsMessengerEXT: return "DebugUtilsMessengerEXT";
case vk::ObjectType::eAccelerationStructureKHR: return "AccelerationStructureKHR";
case vk::ObjectType::eValidationCacheEXT: return "ValidationCacheEXT";
case vk::ObjectType::eAccelerationStructureNV: return "AccelerationStructureNV";
case vk::ObjectType::ePerformanceConfigurationINTEL: return "PerformanceConfigurationINTEL";
case vk::ObjectType::eDeferredOperationKHR: return "DeferredOperationKHR";
case vk::ObjectType::eIndirectCommandsLayoutNV: return "IndirectCommandsLayoutNV";
# if defined( VK_USE_PLATFORM_FUCHSIA )
case vk::ObjectType::eBufferCollectionFUCHSIA: return "BufferCollectionFUCHSIA";
# endif /*VK_USE_PLATFORM_FUCHSIA*/
default: return "invalid ( " + VULKAN_HPP_NAMESPACE::toHexString( static_cast<uint32_t>( value ) ) + " )";
}
}
} // namespace local
#endif
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData,
@@ -379,50 +470,49 @@ namespace vk
}
#endif
#if defined( VULKAN_HPP_NO_TO_STRING )
std::cerr << local::to_string( static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>( messageSeverity ) ) << ": "
<< local::to_string( static_cast<vk::DebugUtilsMessageTypeFlagsEXT>( messageTypes ) ) << ":\n";
#else
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";
#endif
std::cerr << std::string( "\t" ) << "messageIDName = <" << pCallbackData->pMessageIdName << ">\n";
std::cerr << std::string( "\t" ) << "messageIdNumber = " << pCallbackData->messageIdNumber << "\n";
std::cerr << std::string( "\t" ) << "message = <" << pCallbackData->pMessage << ">\n";
if ( 0 < pCallbackData->queueLabelCount )
{
std::cerr << "\t"
<< "Queue Labels:\n";
std::cerr << std::string( "\t" ) << "Queue Labels:\n";
for ( uint32_t i = 0; i < pCallbackData->queueLabelCount; i++ )
{
std::cerr << "\t\t"
<< "labelName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
std::cerr << std::string( "\t\t" ) << "labelName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
}
}
if ( 0 < pCallbackData->cmdBufLabelCount )
{
std::cerr << "\t"
<< "CommandBuffer Labels:\n";
std::cerr << std::string( "\t" ) << "CommandBuffer Labels:\n";
for ( uint32_t i = 0; i < pCallbackData->cmdBufLabelCount; i++ )
{
std::cerr << "\t\t"
<< "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
std::cerr << std::string( "\t\t" ) << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
}
}
if ( 0 < pCallbackData->objectCount )
{
std::cerr << "\t"
<< "Objects:\n";
std::cerr << std::string( "\t" ) << "Objects:\n";
for ( uint32_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";
std::cerr << std::string( "\t\t" ) << "Object " << i << "\n";
#if defined( VULKAN_HPP_NO_TO_STRING )
std::cerr << std::string( "\t\t\t" ) << "objectType = " << local::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) )
<< "\n";
#else
std::cerr << std::string( "\t\t\t" ) << "objectType = " << vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) )
<< "\n";
#endif
std::cerr << std::string( "\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 << std::string( "\t\t\t" ) << "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
}
}
}