Merge pull request #36320 from madmiraal/fix-c4996-warning-vulkan_context

Fix VisualStudio throwing multiple C4996 warnings in vulkan_context.cpp.
This commit is contained in:
Rémi Verschelde 2020-02-18 13:57:57 +01:00 committed by GitHub
commit c3f4c1baed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,8 +30,8 @@
#include "vulkan_context.h" #include "vulkan_context.h"
#include "core/engine.h" #include "core/engine.h"
#include "core/print_string.h"
#include "core/project_settings.h" #include "core/project_settings.h"
#include "core/ustring.h"
#include "core/version.h" #include "core/version.h"
#include "vk_enum_string_helper.h" #include "vk_enum_string_helper.h"
#include <stdio.h> #include <stdio.h>
@ -46,94 +46,99 @@ VKAPI_ATTR VkBool32 VKAPI_CALL VulkanContext::_debug_messenger_callback(VkDebugU
VkDebugUtilsMessageTypeFlagsEXT messageType, VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData) { void *pUserData) {
char prefix[64] = "";
char *message = (char *)malloc(strlen(pCallbackData->pMessage) + 5000);
ERR_FAIL_COND_V(!message, false);
//This error needs to be ignored because the AMD allocator will mix up memory types on IGP processors //This error needs to be ignored because the AMD allocator will mix up memory types on IGP processors
if (strstr(pCallbackData->pMessage, "Mapping an image with layout") != NULL && if (strstr(pCallbackData->pMessage, "Mapping an image with layout") != NULL &&
strstr(pCallbackData->pMessage, "can result in undefined behavior if this memory is used by the device") != NULL) { strstr(pCallbackData->pMessage, "can result in undefined behavior if this memory is used by the device") != NULL) {
free(message);
return VK_FALSE; return VK_FALSE;
} }
// This needs to be ignored because Validator is wrong here // This needs to be ignored because Validator is wrong here
if (strstr(pCallbackData->pMessage, "SPIR-V module not valid: Pointer operand") != NULL && if (strstr(pCallbackData->pMessage, "SPIR-V module not valid: Pointer operand") != NULL &&
strstr(pCallbackData->pMessage, "must be a memory object") != NULL) { strstr(pCallbackData->pMessage, "must be a memory object") != NULL) {
free(message);
return VK_FALSE; return VK_FALSE;
} }
if (strstr(pCallbackData->pMessageIdName, "UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw") != NULL) { if (strstr(pCallbackData->pMessageIdName, "UNASSIGNED-CoreValidation-DrawState-ClearCmdBeforeDraw") != NULL) {
free(message);
return VK_FALSE; return VK_FALSE;
} }
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { String severity_string;
strcat(prefix, "VERBOSE : "); switch (messageSeverity) {
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
strcat(prefix, "INFO : "); severity_string = "VERBOSE : ";
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { break;
strcat(prefix, "WARNING : "); case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { severity_string = "INFO : ";
strcat(prefix, "ERROR : "); break;
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
severity_string = "WARNING : ";
break;
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT:
severity_string = "ERROR : ";
break;
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT:
break;
} }
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) { String type_string;
strcat(prefix, "GENERAL"); switch (messageType) {
} else { case (VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT):
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) { type_string = "GENERAL";
strcat(prefix, "VALIDATION"); break;
//validation_error = 1; case (VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT):
} type_string = "VALIDATION";
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) { break;
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) { case (VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT):
strcat(prefix, "|"); type_string = "PERFORMANCE";
} break;
strcat(prefix, "PERFORMANCE"); case (VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT):
} type_string = "VALIDATION|PERFORMANCE";
break;
} }
sprintf(message, "%s - Message Id Number: %d | Message Id Name: %s\n\t%s\n", prefix, pCallbackData->messageIdNumber, String objects_string;
pCallbackData->pMessageIdName, pCallbackData->pMessage);
if (pCallbackData->objectCount > 0) { if (pCallbackData->objectCount > 0) {
char tmp_message[500]; objects_string = "\n\tObjects - " + String::num_int64(pCallbackData->objectCount);
sprintf(tmp_message, "\n\tObjects - %d\n", pCallbackData->objectCount);
strcat(message, tmp_message);
for (uint32_t object = 0; object < pCallbackData->objectCount; ++object) { for (uint32_t object = 0; object < pCallbackData->objectCount; ++object) {
objects_string +=
"\n\t\tObject[" + String::num_int64(object) + "]" +
" - " + string_VkObjectType(pCallbackData->pObjects[object].objectType) +
", Handle " + String::num_int64(pCallbackData->pObjects[object].objectHandle);
if (NULL != pCallbackData->pObjects[object].pObjectName && strlen(pCallbackData->pObjects[object].pObjectName) > 0) { if (NULL != pCallbackData->pObjects[object].pObjectName && strlen(pCallbackData->pObjects[object].pObjectName) > 0) {
sprintf(tmp_message, "\t\tObject[%d] - %s, Handle %p, Name \"%s\"\n", object, objects_string += ", Name \"" + String(pCallbackData->pObjects[object].pObjectName) + "\"";
string_VkObjectType(pCallbackData->pObjects[object].objectType),
(void *)(pCallbackData->pObjects[object].objectHandle), pCallbackData->pObjects[object].pObjectName);
} else {
sprintf(tmp_message, "\t\tObject[%d] - %s, Handle %p\n", object,
string_VkObjectType(pCallbackData->pObjects[object].objectType),
(void *)(pCallbackData->pObjects[object].objectHandle));
}
strcat(message, tmp_message);
} }
} }
}
String labels_string;
if (pCallbackData->cmdBufLabelCount > 0) { if (pCallbackData->cmdBufLabelCount > 0) {
char tmp_message[500]; labels_string = "\n\tCommand Buffer Labels - " + String::num_int64(pCallbackData->cmdBufLabelCount);
sprintf(tmp_message, "\n\tCommand Buffer Labels - %d\n", pCallbackData->cmdBufLabelCount);
strcat(message, tmp_message);
for (uint32_t cmd_buf_label = 0; cmd_buf_label < pCallbackData->cmdBufLabelCount; ++cmd_buf_label) { for (uint32_t cmd_buf_label = 0; cmd_buf_label < pCallbackData->cmdBufLabelCount; ++cmd_buf_label) {
sprintf(tmp_message, "\t\tLabel[%d] - %s { %f, %f, %f, %f}\n", cmd_buf_label, labels_string +=
pCallbackData->pCmdBufLabels[cmd_buf_label].pLabelName, pCallbackData->pCmdBufLabels[cmd_buf_label].color[0], "\n\t\tLabel[" + String::num_int64(cmd_buf_label) + "]" +
pCallbackData->pCmdBufLabels[cmd_buf_label].color[1], pCallbackData->pCmdBufLabels[cmd_buf_label].color[2], " - " + pCallbackData->pCmdBufLabels[cmd_buf_label].pLabelName +
pCallbackData->pCmdBufLabels[cmd_buf_label].color[3]); "{ ";
strcat(message, tmp_message); for (int color_idx = 0; color_idx < 4; ++color_idx) {
labels_string += String::num(pCallbackData->pCmdBufLabels[cmd_buf_label].color[color_idx]);
if (color_idx < 3) {
labels_string += ", ";
}
}
labels_string += " }";
} }
} }
ERR_PRINT(message); String error_message(severity_string + type_string +
" - Message Id Number: " + String::num_int64(pCallbackData->messageIdNumber) +
" | Message Id Name: " + pCallbackData->pMessageIdName +
"\n\t" + pCallbackData->pMessage +
objects_string + labels_string);
free(message); ERR_PRINT(error_message);
if (Engine::get_singleton()->is_abort_on_gpu_errors_enabled()) { CRASH_COND_MSG(Engine::get_singleton()->is_abort_on_gpu_errors_enabled(),
abort(); "Crashing, because abort on GPU errors is enabled.");
}
// Don't bail out, but keep going. return VK_FALSE;
return false;
} }
VkBool32 VulkanContext::_check_layers(uint32_t check_count, const char **check_names, uint32_t layer_count, VkLayerProperties *layers) { VkBool32 VulkanContext::_check_layers(uint32_t check_count, const char **check_names, uint32_t layer_count, VkLayerProperties *layers) {