CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/GPU/Vulkan/VulkanDebug.cpp
Views: 1401
// Copyright (c) 2016- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include <string>18#include <sstream>19#include <map>20#include <mutex>2122#include "Common/Log.h"23#include "Common/System/System.h"24#include "Common/GPU/Vulkan/VulkanContext.h"25#include "Common/GPU/Vulkan/VulkanDebug.h"2627const int MAX_SAME_ERROR_COUNT = 10;2829// Used to stop outputting the same message over and over.30static std::map<int, int> g_errorCount;31std::mutex g_errorCountMutex;3233// TODO: Call this when launching games in some clean way.34void VulkanClearValidationErrorCounts() {35std::lock_guard<std::mutex> lock(g_errorCountMutex);36g_errorCount.clear();37}3839VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugUtilsCallback(40VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,41VkDebugUtilsMessageTypeFlagsEXT messageType,42const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,43void *pUserData) {44const VulkanLogOptions *options = (const VulkanLogOptions *)pUserData;45std::ostringstream message;4647const char *pMessage = pCallbackData->pMessage;4849int messageCode = pCallbackData->messageIdNumber;50switch (messageCode) {51case 101294395:52// UNASSIGNED-CoreValidation-Shader-OutputNotConsumed - benign perf warning53return false;54case 1303270965:55// Benign perf warning, image blit using GENERAL layout.56// TODO: Oops, turns out we filtered out a bit too much here!57// We really need that performance flag check to sort out the stuff that matters.58// Will enable it soon, but it'll take some fixing.59//60if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)61return false;62break;6364case -375211665:65// VUID-vkAllocateMemory-pAllocateInfo-0171366// Can happen when VMA aggressively tries to allocate aperture memory for upload. It gracefully67// falls back to regular video memory, so we just ignore this. I'd argue this is a VMA bug, actually.68return false;69case 657182421:70// Extended validation (ARM best practices)71// Non-fifo validation not recommended72return false;73case 672904502:74// ARM best practices: index buffer usage warning (too few indices used compared to value range).75// This should be looked into more - happens even in moppi-flower which is weird.76return false;77case 337425955:78// False positive79// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/361580return false;81case 227275665:82// PowerVR (and all other) best practices: LOAD_OP_LOAD used in render pass.83return false;84case 1835555994: // [AMD] [NVIDIA] Performance warning : Pipeline VkPipeline 0xa808d50000000033[global_texcolor] was bound twice in the frame.85// Benign perf warnings.86return false;8788case 1243445977:89// Clear value but no LOAD_OP_CLEAR. Not worth fixing right now.90return false;9192case 1544472022:93// MSAA depth resolve write-after-write??94return false;9596case -1306653903:97// ARM complaint about non-fifo swapchain98return false;99100default:101break;102}103104/*105// Can be used to temporarily turn errors into info for easier debugging.106switch (messageCode) {107case 1544472022:108if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {109messageSeverity = (VkDebugUtilsMessageSeverityFlagBitsEXT)((messageSeverity & ~VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT);110}111break;112default:113break;114}115*/116117int count;118{119std::lock_guard<std::mutex> lock(g_errorCountMutex);120count = g_errorCount[messageCode]++;121}122if (count == MAX_SAME_ERROR_COUNT) {123WARN_LOG(Log::G3D, "Too many validation messages with message %d, stopping", messageCode);124}125if (count >= MAX_SAME_ERROR_COUNT) {126return false;127}128129if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {130message << "ERROR(";131} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {132message << "WARNING(";133} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {134message << "INFO(";135} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {136message << "VERBOSE(";137}138139if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) {140message << "perf";141} else if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) {142message << "general";143} else if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) {144message << "validation";145}146message << ":" << messageCode << ") " << pMessage << "\n";147148std::string msg = message.str();149150#ifdef _WIN32151OutputDebugStringA(msg.c_str());152if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {153if (options->breakOnError && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {154DebugBreak();155}156if (options->msgBoxOnError) {157MessageBoxA(NULL, pMessage, "Alert", MB_OK);158}159} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {160// Don't break on perf warnings for now, even with a debugger. We log them at least.161if (options->breakOnWarning && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT) && 0 == (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)) {162DebugBreak();163}164}165#endif166167if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {168ERROR_LOG(Log::G3D, "VKDEBUG: %s", msg.c_str());169} else {170WARN_LOG(Log::G3D, "VKDEBUG: %s", msg.c_str());171}172173// false indicates that layer should not bail-out of an174// API call that had validation failures. This may mean that the175// app dies inside the driver due to invalid parameter(s).176// That's what would happen without validation layers, so we'll177// keep that behavior here.178return false;179}180181182