<commit_before>/*
* Vulkan examples debug wrapper
* 
* Appendix for VK_EXT_Debug_Report can be found at https://github.com/KhronosGroup/Vulkan-Docs/blob/1.0-VK_EXT_debug_report/doc/specs/vulkan/appendices/debug_report.txt
*
* Copyright (C) 2016 by <NAME> - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#include <sstream>

#include "VulkanUtilities/VulkanDebug.h"
#include "Errors.h"
#include "DebugUtilities.h"

namespace VulkanUtilities
{
    static PFN_vkCreateDebugUtilsMessengerEXT  CreateDebugUtilsMessengerEXT  = nullptr;
    static PFN_vkDestroyDebugUtilsMessengerEXT DestroyDebugUtilsMessengerEXT = nullptr;
    static PFN_vkSetDebugUtilsObjectNameEXT    SetDebugUtilsObjectNameEXT    = nullptr;
    static PFN_vkSetDebugUtilsObjectTagEXT     SetDebugUtilsObjectTagEXT     = nullptr;
    static PFN_vkQueueBeginDebugUtilsLabelEXT  QueueBeginDebugUtilsLabelEXT  = nullptr;
    static PFN_vkQueueEndDebugUtilsLabelEXT    QueueEndDebugUtilsLabelEXT    = nullptr;
    static PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsertDebugUtilsLabelEXT = nullptr;
    static PFN_vkCmdBeginDebugUtilsLabelEXT    CmdBeginDebugUtilsLabelEXT    = nullptr;
    static PFN_vkCmdEndDebugUtilsLabelEXT      CmdEndDebugUtilsLabelEXT      = nullptr;
    static PFN_vkCmdInsertDebugUtilsLabelEXT   CmdInsertDebugUtilsLabelEXT   = nullptr;

    static VkDebugUtilsMessengerEXT            DbgMessenger                  = VK_NULL_HANDLE;

    VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT      messageSeverity,
                                                          VkDebugUtilsMessageTypeFlagsEXT             messageType,
                                                          const VkDebugUtilsMessengerCallbackDataEXT* callbackData,
                                                          void*                                       userData)
    {
        std::stringstream debugMessage;

        // Ignore the following performance warnings:
        // 64: vkCmdClearAttachments() issued on command buffer object 0x... prior to any Draw Cmds. It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.
        // 26: Vertex buffers are bound to command buffer (0x...) but no vertex buffers are attached to this Pipeline State Object (0x...).
        if ((messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) && 
            (callbackData->messageIdNumber == 64 || callbackData->messageIdNumber == 26))
            return VK_FALSE;
            
        debugMessage << "Vulkan debug message (";

        Diligent::DebugMessageSeverity MsgSeverity = Diligent::DebugMessageSeverity::Info;
        if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT)
        {
            debugMessage << "verbose";
            MsgSeverity = Diligent::DebugMessageSeverity::Info;
        }
        else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT)
        {
            debugMessage << "info";
            MsgSeverity = Diligent::DebugMessageSeverity::Info;
        }
        else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
        {
            debugMessage << "WARNING";
            MsgSeverity = Diligent::DebugMessageSeverity::Warning;
        }
        else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
        {
            debugMessage << "ERROR";
            MsgSeverity = Diligent::DebugMessageSeverity::Error;
        }
        else 
        {
            debugMessage << "unknown severity";
            MsgSeverity = Diligent::DebugMessageSeverity::Info;
        }

        if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT)
            debugMessage << ", general";
        if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT)
            debugMessage << ", validation";
        if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
            debugMessage << ", perf";
        
        debugMessage << "): " << "Message Id: " << callbackData->messageIdNumber;
        if (callbackData->pMessageIdName != nullptr)
        {
            debugMessage << " | Message Name: " << callbackData->pMessageIdName;
        }
        if (callbackData->pMessage != nullptr)
        {
            debugMessage << std::endl << "                 " << callbackData->pMessage;
        }

        if (callbackData->objectCount > 0)
        {
            for (uint32_t obj = 0; obj < callbackData->objectCount; ++obj)
            {
                const auto& Object = callbackData->pObjects[obj];
                debugMessage << std::endl << "                 Object[" << obj << "] (" << VkObjectTypeToString(Object.objectType)
                             << "): Handle " << std::hex << "0x" << Object.objectHandle;<commit_msg>Updated vulkan debug message handling<commit_after>/*
* Vulkan examples debug wrapper
* 
* Appendix for VK_EXT_Debug_Report can be found at https://github.com/KhronosGroup/Vulkan-Docs/blob/1.0-VK_EXT_debug_report/doc/specs/vulkan/appendices/debug_report.txt
*
* Copyright (C) 2016 by <NAME> - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#include <sstream>

#include "VulkanUtilities/VulkanDebug.h"
#include "Errors.h"
#include "DebugUtilities.h"

namespace VulkanUtilities
{
    static PFN_vkCreateDebugUtilsMessengerEXT  CreateDebugUtilsMessengerEXT  = nullptr;
    static PFN_vkDestroyDebugUtilsMessengerEXT DestroyDebugUtilsMessengerEXT = nullptr;
    static PFN_vkSetDebugUtilsObjectNameEXT    SetDebugUtilsObjectNameEXT    = nullptr;
    static PFN_vkSetDebugUtilsObjectTagEXT     SetDebugUtilsObjectTagEXT     = nullptr;
    static PFN_vkQueueBeginDebugUtilsLabelEXT  QueueBeginDebugUtilsLabelEXT  = nullptr;
    static PFN_vkQueueEndDebugUtilsLabelEXT    QueueEndDebugUtilsLabelEXT    = nullptr;
    static PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsertDebugUtilsLabelEXT = nullptr;
    static PFN_vkCmdBeginDebugUtilsLabelEXT    CmdBeginDebugUtilsLabelEXT    = nullptr;
    static PFN_vkCmdEndDebugUtilsLabelEXT      CmdEndDebugUtilsLabelEXT      = nullptr;
    static PFN_vkCmdInsertDebugUtilsLabelEXT   CmdInsertDebugUtilsLabelEXT   = nullptr;

    static VkDebugUtilsMessengerEXT            DbgMessenger                  = VK_NULL_HANDLE;

    VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT      messageSeverity,
                                                          VkDebugUtilsMessageTypeFlagsEXT             messageType,
                                                          const VkDebugUtilsMessengerCallbackDataEXT* callbackData,
                                                          void*                                       userData)
    {
        std::stringstream debugMessage;

        // Ignore some validation messages
        if ((messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT))
        {
            {
                // UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw:
                // vkCmdClearAttachments() issued on command buffer object 0x... prior to any Draw Cmds. It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.
                static const char* ClearCmdBeforeDrawIdName             = "UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw";
                constexpr int32_t  DeprecatedClearCmdBeforeDrawIdNumber = 64; // Starting with sdk version 1.1.85, messageIdNumber is 0 for all messages
                if ((callbackData->pMessageIdName != nullptr && strcmp(callbackData->pMessageIdName, ClearCmdBeforeDrawIdName) == 0) || callbackData->messageIdNumber == DeprecatedClearCmdBeforeDrawIdNumber)
                    return VK_FALSE;
            }
        }
            
        Diligent::DebugMessageSeverity MsgSeverity = Diligent::DebugMessageSeverity::Info;
        if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT)
        {
            MsgSeverity = Diligent::DebugMessageSeverity::Info;
        }
        else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT)
        {
            MsgSeverity = Diligent::DebugMessageSeverity::Info;
        }
        else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
        {
            MsgSeverity = Diligent::DebugMessageSeverity::Warning;
        }
        else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
        {
            MsgSeverity = Diligent::DebugMessageSeverity::Error;
        }
        else 
        {
            MsgSeverity = Diligent::DebugMessageSeverity::Info;
        }

        debugMessage << "Vulkan debug message (";
        if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT)
        {
            debugMessage << "general";
            if (messageType & (VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT))
                debugMessage << ", ";
        }
        if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT)
        {
            debugMessage << "validation";
            if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
                debugMessage << ", ";
        }
        if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
            debugMessage << "performance";
        debugMessage << "): ";

        // callbackData->messageIdNumber is deprecated and starting with version 1.1.85 it is always 0
        debugMessage << (callbackData->pMessageIdName != nullptr ? callbackData->pMessageIdName : "<Unknown name>");
        if (callbackData->pMessage != nullptr)
        {
            debugMessage << std::endl << "                 " << callbackData->pMessage;
        }

        if (callbackData->objectCount > 0)
        {
            for (uint32_t obj = 0; obj < callbackData->objectCount; ++obj)
            {
                const auto& Object = callbackData->pObjects[obj];
                debugMessage << std::endl << "                 Object[" << obj << "] (" << VkObjectTypeToString(Object.objectType)
                             << "): Handle " << std::hex << "0x" << Object.objectHandle;
{'fraction_non_alphanumeric': 0.07536907536907538, 'fraction_numerical': 0.005147630147630148, 'mean_word_length': 2.494061757719715, 'pattern_counts': {'":': 0, '<': 102, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5628594', 'n_tokens_mistral': 2982, 'n_tokens_neox': 2848, 'n_words': 525}