diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-03-17 02:17:19 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-03-17 02:17:19 +0000 |
| commit | 632b9844c97e14854d52f5595b9c05c8e115a3a5 (patch) | |
| tree | 0bc49a8add7ad8ff4021e382fede46983aebd2ba /Graphics/GraphicsEngineVulkan | |
| parent | Updated cmake scripts with Vulkan defines (diff) | |
| download | DiligentCore-632b9844c97e14854d52f5595b9c05c8e115a3a5.tar.gz DiligentCore-632b9844c97e14854d52f5595b9c05c8e115a3a5.zip | |
Implemented Vulkan instance initialization; added vulkan debug utils
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
5 files changed, 487 insertions, 4 deletions
diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index d3eb99fc..5c9658d7 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -30,6 +30,7 @@ set(INCLUDE include/SwapChainVkImpl.h include/TextureVkImpl.h include/TextureViewVkImpl.h + include/VulkanUtilities/VulkanDebug.h ) set(INTERFACE @@ -75,6 +76,7 @@ set(SRC src/SwapChainVkImpl.cpp src/TextureVkImpl.cpp src/TextureViewVkImpl.cpp + src/VulkanUtilities/VulkanDebug.cpp ) #set(SHADERS @@ -125,12 +127,14 @@ target_include_directories(GraphicsEngineVk-static PRIVATE #${CMAKE_CURRENT_BINARY_DIR}/CompiledShaders include + ../../External/vulkan ) target_include_directories(GraphicsEngineVk-shared PRIVATE #${CMAKE_CURRENT_BINARY_DIR}/CompiledShaders include + ../../External/vulkan ) set(PRIVATE_DEPENDENCIES @@ -140,6 +144,11 @@ set(PRIVATE_DEPENDENCIES GraphicsEngine ) +if(PLATFORM_WIN32) + find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan PATHS ../../External/vulkan/) + list(APPEND PRIVATE_DEPENDENCIES ${Vulkan_LIBRARY}) +endif() + set(PUBLIC_DEPENDENCIES GraphicsEngineVkInterface ) @@ -149,6 +158,13 @@ target_link_libraries(GraphicsEngineVk-static PRIVATE ${PRIVATE_DEPENDENCIES} PU target_link_libraries(GraphicsEngineVk-shared PRIVATE ${PRIVATE_DEPENDENCIES} PUBLIC ${PUBLIC_DEPENDENCIES}) target_compile_definitions(GraphicsEngineVk-shared PUBLIC ENGINE_DLL=1) + +if(PLATFORM_WIN32) + set(PRIVATE_COMPILE_DEFINITIONS VK_USE_PLATFORM_WIN32_KHR=1) +endif() +target_compile_definitions(GraphicsEngineVk-shared PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) +target_compile_definitions(GraphicsEngineVk-static PRIVATE ${PRIVATE_COMPILE_DEFINITIONS}) + # Set output name to GraphicsEngineVk_{32|64}{r|d} set_dll_output_name(GraphicsEngineVk-shared GraphicsEngineVk) diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h new file mode 100644 index 00000000..bd213544 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanDebug.h @@ -0,0 +1,81 @@ +#pragma once + +#include "vulkan.h" + +namespace VulkanUtilities +{ + // Default validation layers +#if !PLATFORM_ANDROID + // On desktop the LunarG loaders exposes a meta layer that contains all layers + static constexpr const char* ValidationLayerNames[] = + { + "VK_LAYER_LUNARG_standard_validation" + }; +#else + // On Android we need to explicitly select all layers + static constexpr const char *ValidationLayerNames[] = + { + "VK_LAYER_GOOGLE_threading", + "VK_LAYER_LUNARG_parameter_validation", + "VK_LAYER_LUNARG_object_tracker", + "VK_LAYER_LUNARG_core_validation", + "VK_LAYER_LUNARG_swapchain", + "VK_LAYER_GOOGLE_unique_objects" + }; +#endif + + // Load debug function pointers and set debug callback + // if callBack is NULL, default message callback will be used + void SetupDebugging( + VkInstance instance, + VkDebugReportFlagsEXT flags, + VkDebugReportCallbackEXT callBack); + // Clear debug callback + void FreeDebugCallback(VkInstance instance); + + // Setup and functions for the VK_EXT_debug_marker_extension + // Extension spec can be found at https://github.com/KhronosGroup/Vulkan-Docs/blob/1.0-VK_EXT_debug_marker/doc/specs/vulkan/appendices/VK_EXT_debug_marker.txt + // Note that the extension will only be present if run from an offline debugging application + // The actual check for extension presence and enabling it on the device is done in the example base class + // See VulkanExampleBase::createInstance and VulkanExampleBase::createDevice (base/vulkanexamplebase.cpp) + + // Get function pointers for the debug report extensions from the device + void SetupDebugMarkers(VkDevice device); + + // Sets the debug name of an object + // All Objects in Vulkan are represented by their 64-bit handles which are passed into this function + // along with the object type + void SetObjectName(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name); + + // Set the tag for an object + void SetObjectTag(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag); + + // Start a new debug marker region + //void BeginRegion(VkCommandBuffer cmdbuffer, const char* pMarkerName, glm::vec4 color); + + // Insert a new debug marker into the command buffer + //void Insert(VkCommandBuffer cmdbuffer, std::string markerName, glm::vec4 color); + + // End the current debug marker region + //void EndRegion(VkCommandBuffer cmdBuffer); + + // Object specific naming functions + void SetCommandBufferName(VkDevice device, VkCommandBuffer cmdBuffer, const char * name); + void SetQueueName(VkDevice device, VkQueue queue, const char * name); + void SetImageName(VkDevice device, VkImage image, const char * name); + void SetSamplerName(VkDevice device, VkSampler sampler, const char * name); + void SetBufferName(VkDevice device, VkBuffer buffer, const char * name); + void SetDeviceMemoryName(VkDevice device, VkDeviceMemory memory, const char * name); + void SetShaderModuleName(VkDevice device, VkShaderModule shaderModule, const char * name); + void SetPipelineName(VkDevice device, VkPipeline pipeline, const char * name); + void SetPipelineLayoutName(VkDevice device, VkPipelineLayout pipelineLayout, const char * name); + void SetRenderPassName(VkDevice device, VkRenderPass renderPass, const char * name); + void SetFramebufferName(VkDevice device, VkFramebuffer framebuffer, const char * name); + void SetDescriptorSetLayoutName(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const char * name); + void SetDescriptorSetName(VkDevice device, VkDescriptorSet descriptorSet, const char * name); + void SetSemaphoreName(VkDevice device, VkSemaphore semaphore, const char * name); + void SetFenceName(VkDevice device, VkFence fence, const char * name); + void SetEventName(VkDevice device, VkEvent _event, const char * name); + + const char* VkResultToString(VkResult errorCode); +} diff --git a/Graphics/GraphicsEngineVulkan/include/pch.h b/Graphics/GraphicsEngineVulkan/include/pch.h index b4973316..ec0f4b00 100644 --- a/Graphics/GraphicsEngineVulkan/include/pch.h +++ b/Graphics/GraphicsEngineVulkan/include/pch.h @@ -31,11 +31,11 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define NOMINMAX - #include <vector> #include <exception> #include <algorithm> -//#include <vulkan.h> + +#include "vulkan.h" #include "PlatformDefinitions.h" #include "Errors.h" @@ -44,4 +44,19 @@ //#include "D3DErrors.h" #include "RenderDeviceBase.h" #include "ValidatedCast.h" -#include <atlcomcli.h>
\ No newline at end of file +#include <atlcomcli.h> + +#define CHECK_VK_ERROR(err, ...)\ +{ \ + if( err < 0 ) \ + { \ + LogError<false>(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nVK Error: ", VulkanUtilities::VkResultToString(err)); \ + UNEXPECTED("Error"); \ + } \ +} + +#define CHECK_VK_ERROR_AND_THROW(err, ...)\ +{ \ + if( err < 0 ) \ + LogError<true>(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nVK Error Code: ", VulkanUtilities::VkResultToString(err)); \ +} diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp index 19803a52..eb18298b 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp @@ -33,6 +33,7 @@ #include "StringTools.h" #include "EngineMemory.h" #include "CommandQueueVkImpl.h" +#include "VulkanUtilities/VulkanDebug.h" namespace Diligent { @@ -65,6 +66,8 @@ public: const SwapChainDesc& SwapChainDesc, void* pNativeWndHandle, ISwapChain **ppSwapChain )override final; +private: + void CreateVulkanInstance(const EngineVkAttribs& CreationAttribs, VkInstance &instance); }; @@ -99,7 +102,68 @@ void GetHardwareAdapter(IDXGIFactory2* pFactory, IDXGIAdapter1** ppAdapter) } #endif -/// Creates render device and device contexts for Direct3D12-based engine implementation +void EngineFactoryVkImpl::CreateVulkanInstance(const EngineVkAttribs& CreationAttribs, VkInstance &instance) +{ + bool EnableValidation = CreationAttribs.EnableValidation; +#ifdef _DEBUG + EnableValidation = true; +#endif + + VkApplicationInfo appInfo = {}; + appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + appInfo.pNext = nullptr; // Pointer to an extension-specific structure. + appInfo.pApplicationName = nullptr; + appInfo.applicationVersion = 0; // Developer-supplied version number of the application + appInfo.pEngineName = "Diligent Engine"; + appInfo.engineVersion = 0;// Developer-supplied version number of the engine used to create the application. + appInfo.apiVersion = VK_API_VERSION_1_0; + + std::vector<const char*> GlobalExtensions = { VK_KHR_SURFACE_EXTENSION_NAME }; + + // Enable surface extensions depending on os +#if defined(VK_USE_PLATFORM_WIN32_KHR) + GlobalExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); +#elif defined(VK_USE_PLATFORM_ANDROID_KHR) + GlobalExtensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); +#elif defined(_DIRECT2DISPLAY) + GlobalExtensions.push_back(VK_KHR_DISPLAY_EXTENSION_NAME); +#elif defined(VK_USE_PLATFORM_WAYLAND_KHR) + GlobalExtensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); +#elif defined(VK_USE_PLATFORM_XCB_KHR) + GlobalExtensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); +#elif defined(VK_USE_PLATFORM_IOS_MVK) + GlobalExtensions.push_back(VK_MVK_IOS_SURFACE_EXTENSION_NAME); +#elif defined(VK_USE_PLATFORM_MACOS_MVK) + GlobalExtensions.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME); +#endif + + if (EnableValidation) + { + GlobalExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + } + + for(Uint32 ext = 0; ext < CreationAttribs.GlobalExtensionCount; ++ext) + GlobalExtensions.push_back(CreationAttribs.ppGlobalExtensionNames[ext]); + + VkInstanceCreateInfo InstanceCreateInfo = {}; + InstanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + InstanceCreateInfo.pNext = NULL; // Pointer to an extension-specific structure. + InstanceCreateInfo.flags = 0; // Reserved for future use. + InstanceCreateInfo.pApplicationInfo = &appInfo; + InstanceCreateInfo.enabledExtensionCount = static_cast<uint32_t>(GlobalExtensions.size()); + InstanceCreateInfo.ppEnabledExtensionNames = GlobalExtensions.empty() ? nullptr : GlobalExtensions.data(); + + if (EnableValidation) + { + InstanceCreateInfo.enabledLayerCount = static_cast<uint32_t>(_countof(VulkanUtilities::ValidationLayerNames)); + InstanceCreateInfo.ppEnabledLayerNames = VulkanUtilities::ValidationLayerNames; + } + auto res = vkCreateInstance(&InstanceCreateInfo, reinterpret_cast<VkAllocationCallbacks*>(CreationAttribs.pVkAllocator), &instance); + CHECK_VK_ERROR_AND_THROW(res, "Failed to create Vulkan instance"); +} + + +/// Creates render device and device contexts for Vulkan backend /// \param [in] CreationAttribs - Engine creation attributes. /// \param [out] ppDevice - Address of the memory location where pointer to @@ -121,6 +185,12 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk( const EngineVkAttribs& Crea if( !ppDevice || !ppContexts ) return; + VkInstance instance; + CreateVulkanInstance(CreationAttribs, instance); + + // Vulkan instance + //err = createInstance(settings.validation); + #if 0 for(Uint32 Type=Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; Type < Vk_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++Type) { @@ -318,6 +388,7 @@ void EngineFactoryVkImpl::AttachToVkDevice(void *pVkNativeDevice, } #endif + /// Creates a swap chain for Direct3D12-based engine implementation /// \param [in] pDevice - Pointer to the render device diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp new file mode 100644 index 00000000..42fa7d6f --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp @@ -0,0 +1,300 @@ +/* +* 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 Sascha Willems - 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_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallback = VK_NULL_HANDLE; + static VkDebugReportCallbackEXT msgCallback = VK_NULL_HANDLE; + + VKAPI_ATTR VkBool32 VKAPI_CALL MessageCallback( + VkDebugReportFlagsEXT flags, + VkDebugReportObjectTypeEXT objType, + uint64_t srcObject, + size_t location, + int32_t msgCode, + const char* pLayerPrefix, + const char* pMsg, + void* pUserData) + { + std::stringstream debugMessage; + + debugMessage << "Vulkan debug message"; + + // Select prefix depending on flags passed to the callback + // Note that multiple flags may be set for a single validation message + + // Error that may result in undefined behaviour + if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) + debugMessage << " (ERROR)"; + + // Warnings may hint at unexpected / non-spec API usage + if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) + debugMessage << " (WARNING)"; + + // May indicate sub-optimal usage of the API + if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) + debugMessage << " (Performance)"; + + // Informal messages that may become handy during debugging + if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) + debugMessage << " (Info)"; + + // Diagnostic info from the Vulkan loader and layers + // Usually not helpful in terms of API usage, but may help to debug layer and loader problems + if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) + debugMessage << " (Debug)"; + + debugMessage << " [" << pLayerPrefix << "] Code " << msgCode << "\n" << pMsg << std::endl; + + BasicPlatformDebug::DebugMessageSeverity MsgSeverity = BasicPlatformDebug::DebugMessageSeverity::Info; + if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) + MsgSeverity = BasicPlatformDebug::DebugMessageSeverity::Error; + else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) + MsgSeverity = BasicPlatformDebug::DebugMessageSeverity::Warning; + else + MsgSeverity = BasicPlatformDebug::DebugMessageSeverity::Info; + LOG_DEBUG_MESSAGE(MsgSeverity, debugMessage.str().c_str()); + + // The return value of this callback controls wether the Vulkan call that caused + // the validation message will be aborted or not + // We return VK_FALSE as we DON'T want Vulkan calls that cause a validation message + // (and return a VkResult) to abort + // If you instead want to have calls abort, pass in VK_TRUE and the function will + // return VK_ERROR_VALIDATION_FAILED_EXT + return VK_FALSE; + } + + void SetupDebugging(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportCallbackEXT callBack) + { + auto CreateDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT")); + //auto dbgBreakCallback = reinterpret_cast<PFN_vkDebugReportMessageEXT>(vkGetInstanceProcAddr(instance, "vkDebugReportMessageEXT")); + DestroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT")); + + VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = {}; + dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; + dbgCreateInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)MessageCallback; + dbgCreateInfo.flags = flags; + + VkResult err = CreateDebugReportCallback( + instance, + &dbgCreateInfo, + nullptr, + (callBack != VK_NULL_HANDLE) ? &callBack : &msgCallback); + VERIFY_EXPR(err); + } + + void FreeDebugCallback(VkInstance instance) + { + if (msgCallback != VK_NULL_HANDLE) + { + DestroyDebugReportCallback(instance, msgCallback, nullptr); + } + } + + static PFN_vkDebugMarkerSetObjectTagEXT pfnDebugMarkerSetObjectTag = VK_NULL_HANDLE; + static PFN_vkDebugMarkerSetObjectNameEXT pfnDebugMarkerSetObjectName = VK_NULL_HANDLE; + static PFN_vkCmdDebugMarkerBeginEXT pfnCmdDebugMarkerBegin = VK_NULL_HANDLE; + static PFN_vkCmdDebugMarkerEndEXT pfnCmdDebugMarkerEnd = VK_NULL_HANDLE; + static PFN_vkCmdDebugMarkerInsertEXT pfnCmdDebugMarkerInsert = VK_NULL_HANDLE; + + void SetupDebugMarkers(VkDevice device) + { + pfnDebugMarkerSetObjectTag = reinterpret_cast<PFN_vkDebugMarkerSetObjectTagEXT>(vkGetDeviceProcAddr(device, "vkDebugMarkerSetObjectTagEXT")); + pfnDebugMarkerSetObjectName = reinterpret_cast<PFN_vkDebugMarkerSetObjectNameEXT>(vkGetDeviceProcAddr(device, "vkDebugMarkerSetObjectNameEXT")); + pfnCmdDebugMarkerBegin = reinterpret_cast<PFN_vkCmdDebugMarkerBeginEXT>(vkGetDeviceProcAddr(device, "vkCmdDebugMarkerBeginEXT")); + pfnCmdDebugMarkerEnd = reinterpret_cast<PFN_vkCmdDebugMarkerEndEXT>(vkGetDeviceProcAddr(device, "vkCmdDebugMarkerEndEXT")); + pfnCmdDebugMarkerInsert = reinterpret_cast<PFN_vkCmdDebugMarkerInsertEXT>(vkGetDeviceProcAddr(device, "vkCmdDebugMarkerInsertEXT")); + } + + void SetObjectName(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name) + { + // Check for valid function pointer (may not be present if not running in a debugging application) + if (pfnDebugMarkerSetObjectName != VK_NULL_HANDLE) + { + VkDebugMarkerObjectNameInfoEXT nameInfo = {}; + nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT; + nameInfo.objectType = objectType; + nameInfo.object = object; + nameInfo.pObjectName = name; + pfnDebugMarkerSetObjectName(device, &nameInfo); + } + } + + void SetObjectTag(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag) + { + // Check for valid function pointer (may not be present if not running in a debugging application) + if (pfnDebugMarkerSetObjectTag) + { + VkDebugMarkerObjectTagInfoEXT tagInfo = {}; + tagInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_TAG_INFO_EXT; + tagInfo.objectType = objectType; + tagInfo.object = object; + tagInfo.tagName = name; + tagInfo.tagSize = tagSize; + tagInfo.pTag = tag; + pfnDebugMarkerSetObjectTag(device, &tagInfo); + } + } + + //void beginRegion(VkCommandBuffer cmdbuffer, const char* pMarkerName, glm::vec4 color) + //{ + // // Check for valid function pointer (may not be present if not running in a debugging application) + // if (pfnCmdDebugMarkerBegin) + // { + // VkDebugMarkerMarkerInfoEXT markerInfo = {}; + // markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT; + // memcpy(markerInfo.color, &color[0], sizeof(float) * 4); + // markerInfo.pMarkerName = pMarkerName; + // pfnCmdDebugMarkerBegin(cmdbuffer, &markerInfo); + // } + //} + + //void insert(VkCommandBuffer cmdbuffer, std::string markerName, glm::vec4 color) + //{ + // // Check for valid function pointer (may not be present if not running in a debugging application) + // if (pfnCmdDebugMarkerInsert) + // { + // VkDebugMarkerMarkerInfoEXT markerInfo = {}; + // markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT; + // memcpy(markerInfo.color, &color[0], sizeof(float) * 4); + // markerInfo.pMarkerName = markerName.c_str(); + // pfnCmdDebugMarkerInsert(cmdbuffer, &markerInfo); + // } + //} + + //void endRegion(VkCommandBuffer cmdBuffer) + //{ + // // Check for valid function (may not be present if not runnin in a debugging application) + // if (pfnCmdDebugMarkerEnd) + // { + // pfnCmdDebugMarkerEnd(cmdBuffer); + // } + //} + + void SetCommandBufferName(VkDevice device, VkCommandBuffer cmdBuffer, const char * name) + { + SetObjectName(device, (uint64_t)cmdBuffer, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, name); + } + + void SetQueueName(VkDevice device, VkQueue queue, const char * name) + { + SetObjectName(device, (uint64_t)queue, VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, name); + } + + void SetImageName(VkDevice device, VkImage image, const char * name) + { + SetObjectName(device, (uint64_t)image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, name); + } + + void SetSamplerName(VkDevice device, VkSampler sampler, const char * name) + { + SetObjectName(device, (uint64_t)sampler, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, name); + } + + void SetBufferName(VkDevice device, VkBuffer buffer, const char * name) + { + SetObjectName(device, (uint64_t)buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, name); + } + + void SetDeviceMemoryName(VkDevice device, VkDeviceMemory memory, const char * name) + { + SetObjectName(device, (uint64_t)memory, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, name); + } + + void SetShaderModuleName(VkDevice device, VkShaderModule shaderModule, const char * name) + { + SetObjectName(device, (uint64_t)shaderModule, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, name); + } + + void SetPipelineName(VkDevice device, VkPipeline pipeline, const char * name) + { + SetObjectName(device, (uint64_t)pipeline, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, name); + } + + void SetPipelineLayoutName(VkDevice device, VkPipelineLayout pipelineLayout, const char * name) + { + SetObjectName(device, (uint64_t)pipelineLayout, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, name); + } + + void SetRenderPassName(VkDevice device, VkRenderPass renderPass, const char * name) + { + SetObjectName(device, (uint64_t)renderPass, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, name); + } + + void SetFramebufferName(VkDevice device, VkFramebuffer framebuffer, const char * name) + { + SetObjectName(device, (uint64_t)framebuffer, VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, name); + } + + void SetDescriptorSetLayoutName(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const char * name) + { + SetObjectName(device, (uint64_t)descriptorSetLayout, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, name); + } + + void SetDescriptorSetName(VkDevice device, VkDescriptorSet descriptorSet, const char * name) + { + SetObjectName(device, (uint64_t)descriptorSet, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, name); + } + + void SetSemaphoreName(VkDevice device, VkSemaphore semaphore, const char * name) + { + SetObjectName(device, (uint64_t)semaphore, VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, name); + } + + void SetFenceName(VkDevice device, VkFence fence, const char * name) + { + SetObjectName(device, (uint64_t)fence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, name); + } + + void SetEventName(VkDevice device, VkEvent _event, const char * name) + { + SetObjectName(device, (uint64_t)_event, VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, name); + } + + const char* VkResultToString(VkResult errorCode) + { + switch (errorCode) + { +#define STR(r) case VK_ ##r: return #r + STR(NOT_READY); + STR(TIMEOUT); + STR(EVENT_SET); + STR(EVENT_RESET); + STR(INCOMPLETE); + STR(ERROR_OUT_OF_HOST_MEMORY); + STR(ERROR_OUT_OF_DEVICE_MEMORY); + STR(ERROR_INITIALIZATION_FAILED); + STR(ERROR_DEVICE_LOST); + STR(ERROR_MEMORY_MAP_FAILED); + STR(ERROR_LAYER_NOT_PRESENT); + STR(ERROR_EXTENSION_NOT_PRESENT); + STR(ERROR_FEATURE_NOT_PRESENT); + STR(ERROR_INCOMPATIBLE_DRIVER); + STR(ERROR_TOO_MANY_OBJECTS); + STR(ERROR_FORMAT_NOT_SUPPORTED); + STR(ERROR_SURFACE_LOST_KHR); + STR(ERROR_NATIVE_WINDOW_IN_USE_KHR); + STR(SUBOPTIMAL_KHR); + STR(ERROR_OUT_OF_DATE_KHR); + STR(ERROR_INCOMPATIBLE_DISPLAY_KHR); + STR(ERROR_VALIDATION_FAILED_EXT); + STR(ERROR_INVALID_SHADER_NV); +#undef STR + default: + return "UNKNOWN_ERROR"; + } + } +} |
