From ca29093f647a27839a5019b143fe2cecf8e55e23 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 14 Mar 2020 23:15:30 +0200 Subject: [PATCH] Always compilein validation code --- src/client/refresh/vk/vk_common.c | 31 ++++++--- src/client/refresh/vk/vk_device.c | 91 ++++++++++++++------------- src/client/refresh/vk/vk_rmain.c | 2 +- src/client/refresh/vk/vk_validation.c | 9 ++- 4 files changed, 76 insertions(+), 57 deletions(-) diff --git a/src/client/refresh/vk/vk_common.c b/src/client/refresh/vk/vk_common.c index 6f3c1f67..cdf91cbe 100644 --- a/src/client/refresh/vk/vk_common.c +++ b/src/client/refresh/vk/vk_common.c @@ -1659,14 +1659,27 @@ qboolean QVk_Init(SDL_Window *window) } R_Printf(PRINT_ALL, "...created Vulkan instance\n"); - // initialize function pointers - qvkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk_instance, "vkCreateDebugUtilsMessengerEXT"); - qvkDestroyDebugUtilsMessengerEXT = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk_instance, "vkDestroyDebugUtilsMessengerEXT"); - qvkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(vk_instance, "vkSetDebugUtilsObjectNameEXT"); - qvkSetDebugUtilsObjectTagEXT = (PFN_vkSetDebugUtilsObjectTagEXT)vkGetInstanceProcAddr(vk_instance, "vkSetDebugUtilsObjectTagEXT"); - qvkCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdBeginDebugUtilsLabelEXT"); - qvkCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdEndDebugUtilsLabelEXT"); - qvkInsertDebugUtilsLabelEXT = (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdInsertDebugUtilsLabelEXT"); + if (vk_validation->value) + { + // initialize function pointers + qvkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk_instance, "vkCreateDebugUtilsMessengerEXT"); + qvkDestroyDebugUtilsMessengerEXT = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk_instance, "vkDestroyDebugUtilsMessengerEXT"); + qvkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(vk_instance, "vkSetDebugUtilsObjectNameEXT"); + qvkSetDebugUtilsObjectTagEXT = (PFN_vkSetDebugUtilsObjectTagEXT)vkGetInstanceProcAddr(vk_instance, "vkSetDebugUtilsObjectTagEXT"); + qvkCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdBeginDebugUtilsLabelEXT"); + qvkCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdEndDebugUtilsLabelEXT"); + qvkInsertDebugUtilsLabelEXT = (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdInsertDebugUtilsLabelEXT"); + } + else + { + qvkCreateDebugUtilsMessengerEXT = NULL; + qvkDestroyDebugUtilsMessengerEXT = NULL; + qvkSetDebugUtilsObjectNameEXT = NULL; + qvkSetDebugUtilsObjectTagEXT = NULL; + qvkCmdBeginDebugUtilsLabelEXT = NULL; + qvkCmdEndDebugUtilsLabelEXT = NULL; + qvkInsertDebugUtilsLabelEXT = NULL; + } if (vk_validation->value) QVk_CreateValidationLayers(); @@ -2021,7 +2034,6 @@ void QVk_BeginRenderpass(qvkrenderpasstype_t rpType) } }; -#if defined(_DEBUG) if (rpType == RP_WORLD) { QVk_DebugLabelBegin(&vk_commandbuffers[vk_activeBufferIdx], "Draw World", 0.f, 1.f, 0.f); } @@ -2033,7 +2045,6 @@ void QVk_BeginRenderpass(qvkrenderpasstype_t rpType) QVk_DebugLabelEnd(&vk_commandbuffers[vk_activeBufferIdx]); QVk_DebugLabelBegin(&vk_commandbuffers[vk_activeBufferIdx], "Draw View Warp", 1.f, 0.f, .5f); } -#endif vkCmdBeginRenderPass(vk_commandbuffers[vk_activeBufferIdx], &renderBeginInfo[rpType], VK_SUBPASS_CONTENTS_INLINE); } diff --git a/src/client/refresh/vk/vk_device.c b/src/client/refresh/vk/vk_device.c index e4993399..04d2267b 100644 --- a/src/client/refresh/vk/vk_device.c +++ b/src/client/refresh/vk/vk_device.c @@ -286,68 +286,73 @@ qboolean QVk_CreateDevice(int preferredDeviceIdx) // debug label related functions void QVk_DebugSetObjectName(uint64_t obj, VkObjectType objType, const char *objName) { -#if defined(_DEBUG) - VkDebugUtilsObjectNameInfoEXT oNameInf = { - .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, - .pNext = NULL, - .objectType = objType, - .objectHandle = obj, - .pObjectName = objName - }; + if (qvkSetDebugUtilsObjectNameEXT) + { + VkDebugUtilsObjectNameInfoEXT oNameInf = { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, + .pNext = NULL, + .objectType = objType, + .objectHandle = obj, + .pObjectName = objName + }; - qvkSetDebugUtilsObjectNameEXT(vk_device.logical, &oNameInf); -#endif + qvkSetDebugUtilsObjectNameEXT(vk_device.logical, &oNameInf); + } } void QVk_DebugSetObjectTag(uint64_t obj, VkObjectType objType, uint64_t tagName, size_t tagSize, const void *tagData) { -#if defined(_DEBUG) - VkDebugUtilsObjectTagInfoEXT oTagInf = { - .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_TAG_INFO_EXT, - .pNext = NULL, - .objectType = objType, - .objectHandle = obj, - .tagName = tagName, - .tagSize = tagSize, - .pTag = tagData - }; + if (qvkSetDebugUtilsObjectTagEXT) + { + VkDebugUtilsObjectTagInfoEXT oTagInf = { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_TAG_INFO_EXT, + .pNext = NULL, + .objectType = objType, + .objectHandle = obj, + .tagName = tagName, + .tagSize = tagSize, + .pTag = tagData + }; - qvkSetDebugUtilsObjectTagEXT(vk_device.logical, &oTagInf); -#endif + qvkSetDebugUtilsObjectTagEXT(vk_device.logical, &oTagInf); + } } void QVk_DebugLabelBegin(const VkCommandBuffer *cmdBuffer, const char *labelName, const float r, const float g, const float b) { -#if defined(_DEBUG) - VkDebugUtilsLabelEXT labelInfo = { - .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, - .pNext = NULL, - .pLabelName = labelName, - .color = { r, g, b, 1.f } - }; + if (qvkCmdBeginDebugUtilsLabelEXT) + { + VkDebugUtilsLabelEXT labelInfo = { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, + .pNext = NULL, + .pLabelName = labelName, + .color = { r, g, b, 1.f } + }; - qvkCmdBeginDebugUtilsLabelEXT(*cmdBuffer, &labelInfo); -#endif + qvkCmdBeginDebugUtilsLabelEXT(*cmdBuffer, &labelInfo); + } } void QVk_DebugLabelEnd(const VkCommandBuffer *cmdBuffer) { -#if defined(_DEBUG) - qvkCmdEndDebugUtilsLabelEXT(*cmdBuffer); -#endif + if (qvkCmdEndDebugUtilsLabelEXT) + { + qvkCmdEndDebugUtilsLabelEXT(*cmdBuffer); + } } void QVk_DebugLabelInsert(const VkCommandBuffer *cmdBuffer, const char *labelName, const float r, const float g, const float b) { -#if defined(_DEBUG) - VkDebugUtilsLabelEXT labelInfo = { - .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, - .pNext = NULL, - .pLabelName = labelName, - .color = { r, g, b, 1.f } - }; + if (qvkInsertDebugUtilsLabelEXT) + { + VkDebugUtilsLabelEXT labelInfo = { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, + .pNext = NULL, + .pLabelName = labelName, + .color = { r, g, b, 1.f } + }; - qvkInsertDebugUtilsLabelEXT(*cmdBuffer, &labelInfo); -#endif + qvkInsertDebugUtilsLabelEXT(*cmdBuffer, &labelInfo); + } } diff --git a/src/client/refresh/vk/vk_rmain.c b/src/client/refresh/vk/vk_rmain.c index 75beedbf..011160e5 100644 --- a/src/client/refresh/vk/vk_rmain.c +++ b/src/client/refresh/vk/vk_rmain.c @@ -1060,7 +1060,7 @@ R_Register( void ) r_vsync = ri.Cvar_Get("r_vsync", "0", CVAR_ARCHIVE); vk_overbrightbits = ri.Cvar_Get("vk_overbrightbits", "1.0", CVAR_ARCHIVE); - vk_validation = ri.Cvar_Get("vk_validation", "0", 0); + vk_validation = ri.Cvar_Get("vk_validation", "0", CVAR_ARCHIVE); vk_bitdepth = ri.Cvar_Get("vk_bitdepth", "0", 0); vk_picmip = ri.Cvar_Get("vk_picmip", "0", 0); vk_skymip = ri.Cvar_Get("vk_skymip", "0", 0); diff --git a/src/client/refresh/vk/vk_validation.c b/src/client/refresh/vk/vk_validation.c index 7b26a02d..f45a9412 100644 --- a/src/client/refresh/vk/vk_validation.c +++ b/src/client/refresh/vk/vk_validation.c @@ -83,13 +83,16 @@ void QVk_CreateValidationLayers() VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT; } - VK_VERIFY(qvkCreateDebugUtilsMessengerEXT(vk_instance, &callbackInfo, NULL, &validationMessenger)); - R_Printf(PRINT_ALL, "...Vulkan validation layers enabled\n"); + if (qvkCreateDebugUtilsMessengerEXT) + { + VK_VERIFY(qvkCreateDebugUtilsMessengerEXT(vk_instance, &callbackInfo, NULL, &validationMessenger)); + R_Printf(PRINT_ALL, "...Vulkan validation layers enabled\n"); + } } void QVk_DestroyValidationLayers() { - if( validationMessenger != VK_NULL_HANDLE ) + if( validationMessenger != VK_NULL_HANDLE && qvkDestroyDebugUtilsMessengerEXT) { qvkDestroyDebugUtilsMessengerEXT( vk_instance, validationMessenger, NULL ); validationMessenger = VK_NULL_HANDLE;