CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/Vulkan/VulkanDebug.cpp
Views: 1401
1
// Copyright (c) 2016- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <string>
19
#include <sstream>
20
#include <map>
21
#include <mutex>
22
23
#include "Common/Log.h"
24
#include "Common/System/System.h"
25
#include "Common/GPU/Vulkan/VulkanContext.h"
26
#include "Common/GPU/Vulkan/VulkanDebug.h"
27
28
const int MAX_SAME_ERROR_COUNT = 10;
29
30
// Used to stop outputting the same message over and over.
31
static std::map<int, int> g_errorCount;
32
std::mutex g_errorCountMutex;
33
34
// TODO: Call this when launching games in some clean way.
35
void VulkanClearValidationErrorCounts() {
36
std::lock_guard<std::mutex> lock(g_errorCountMutex);
37
g_errorCount.clear();
38
}
39
40
VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugUtilsCallback(
41
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
42
VkDebugUtilsMessageTypeFlagsEXT messageType,
43
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
44
void *pUserData) {
45
const VulkanLogOptions *options = (const VulkanLogOptions *)pUserData;
46
std::ostringstream message;
47
48
const char *pMessage = pCallbackData->pMessage;
49
50
int messageCode = pCallbackData->messageIdNumber;
51
switch (messageCode) {
52
case 101294395:
53
// UNASSIGNED-CoreValidation-Shader-OutputNotConsumed - benign perf warning
54
return false;
55
case 1303270965:
56
// Benign perf warning, image blit using GENERAL layout.
57
// TODO: Oops, turns out we filtered out a bit too much here!
58
// We really need that performance flag check to sort out the stuff that matters.
59
// Will enable it soon, but it'll take some fixing.
60
//
61
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
62
return false;
63
break;
64
65
case -375211665:
66
// VUID-vkAllocateMemory-pAllocateInfo-01713
67
// Can happen when VMA aggressively tries to allocate aperture memory for upload. It gracefully
68
// falls back to regular video memory, so we just ignore this. I'd argue this is a VMA bug, actually.
69
return false;
70
case 657182421:
71
// Extended validation (ARM best practices)
72
// Non-fifo validation not recommended
73
return false;
74
case 672904502:
75
// ARM best practices: index buffer usage warning (too few indices used compared to value range).
76
// This should be looked into more - happens even in moppi-flower which is weird.
77
return false;
78
case 337425955:
79
// False positive
80
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/3615
81
return false;
82
case 227275665:
83
// PowerVR (and all other) best practices: LOAD_OP_LOAD used in render pass.
84
return false;
85
case 1835555994: // [AMD] [NVIDIA] Performance warning : Pipeline VkPipeline 0xa808d50000000033[global_texcolor] was bound twice in the frame.
86
// Benign perf warnings.
87
return false;
88
89
case 1243445977:
90
// Clear value but no LOAD_OP_CLEAR. Not worth fixing right now.
91
return false;
92
93
case 1544472022:
94
// MSAA depth resolve write-after-write??
95
return false;
96
97
case -1306653903:
98
// ARM complaint about non-fifo swapchain
99
return false;
100
101
default:
102
break;
103
}
104
105
/*
106
// Can be used to temporarily turn errors into info for easier debugging.
107
switch (messageCode) {
108
case 1544472022:
109
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
110
messageSeverity = (VkDebugUtilsMessageSeverityFlagBitsEXT)((messageSeverity & ~VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT);
111
}
112
break;
113
default:
114
break;
115
}
116
*/
117
118
int count;
119
{
120
std::lock_guard<std::mutex> lock(g_errorCountMutex);
121
count = g_errorCount[messageCode]++;
122
}
123
if (count == MAX_SAME_ERROR_COUNT) {
124
WARN_LOG(Log::G3D, "Too many validation messages with message %d, stopping", messageCode);
125
}
126
if (count >= MAX_SAME_ERROR_COUNT) {
127
return false;
128
}
129
130
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
131
message << "ERROR(";
132
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
133
message << "WARNING(";
134
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
135
message << "INFO(";
136
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {
137
message << "VERBOSE(";
138
}
139
140
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) {
141
message << "perf";
142
} else if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) {
143
message << "general";
144
} else if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) {
145
message << "validation";
146
}
147
message << ":" << messageCode << ") " << pMessage << "\n";
148
149
std::string msg = message.str();
150
151
#ifdef _WIN32
152
OutputDebugStringA(msg.c_str());
153
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
154
if (options->breakOnError && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {
155
DebugBreak();
156
}
157
if (options->msgBoxOnError) {
158
MessageBoxA(NULL, pMessage, "Alert", MB_OK);
159
}
160
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
161
// Don't break on perf warnings for now, even with a debugger. We log them at least.
162
if (options->breakOnWarning && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT) && 0 == (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)) {
163
DebugBreak();
164
}
165
}
166
#endif
167
168
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
169
ERROR_LOG(Log::G3D, "VKDEBUG: %s", msg.c_str());
170
} else {
171
WARN_LOG(Log::G3D, "VKDEBUG: %s", msg.c_str());
172
}
173
174
// false indicates that layer should not bail-out of an
175
// API call that had validation failures. This may mean that the
176
// app dies inside the driver due to invalid parameter(s).
177
// That's what would happen without validation layers, so we'll
178
// keep that behavior here.
179
return false;
180
}
181
182