Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/Vulkan/VulkanDebug.cpp
3187 views
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
std::ostringstream message;
46
47
const char *pMessage = pCallbackData->pMessage;
48
49
int messageCode = pCallbackData->messageIdNumber;
50
switch (messageCode) {
51
case 101294395:
52
// UNASSIGNED-CoreValidation-Shader-OutputNotConsumed - benign perf warning
53
return false;
54
case 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
//
60
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
61
return false;
62
break;
63
64
case -375211665:
65
// VUID-vkAllocateMemory-pAllocateInfo-01713
66
// Can happen when VMA aggressively tries to allocate aperture memory for upload. It gracefully
67
// falls back to regular video memory, so we just ignore this. I'd argue this is a VMA bug, actually.
68
return false;
69
case 657182421:
70
// Extended validation (ARM best practices)
71
// Non-fifo validation not recommended
72
return false;
73
case 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.
76
return false;
77
case 227275665:
78
// PowerVR (and all other) best practices: LOAD_OP_LOAD used in render pass.
79
return false;
80
case 1835555994: // [AMD] [NVIDIA] Performance warning : Pipeline VkPipeline 0xa808d50000000033[global_texcolor] was bound twice in the frame.
81
// Benign perf warnings.
82
return false;
83
84
case 1243445977:
85
// Clear value but no LOAD_OP_CLEAR. Not worth fixing right now.
86
return false;
87
88
case 1544472022:
89
// MSAA depth resolve write-after-write??
90
return false;
91
92
case -1306653903:
93
// ARM complaint about non-fifo swapchain
94
return false;
95
96
default:
97
break;
98
}
99
100
/*
101
// Can be used to temporarily turn errors into info for easier debugging.
102
switch (messageCode) {
103
case 1544472022:
104
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
105
messageSeverity = (VkDebugUtilsMessageSeverityFlagBitsEXT)((messageSeverity & ~VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT);
106
}
107
break;
108
default:
109
break;
110
}
111
*/
112
113
int count;
114
{
115
std::lock_guard<std::mutex> lock(g_errorCountMutex);
116
count = g_errorCount[messageCode]++;
117
}
118
if (count == MAX_SAME_ERROR_COUNT) {
119
WARN_LOG(Log::G3D, "Too many validation messages with message %d, stopping", messageCode);
120
}
121
if (count >= MAX_SAME_ERROR_COUNT) {
122
return false;
123
}
124
125
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
126
message << "ERROR(";
127
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
128
message << "WARNING(";
129
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
130
message << "INFO(";
131
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {
132
message << "VERBOSE(";
133
}
134
135
if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) {
136
message << "perf";
137
} else if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) {
138
message << "general";
139
} else if (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) {
140
message << "validation";
141
}
142
message << ":" << messageCode << ") " << pMessage << "\n";
143
144
std::string msg = message.str();
145
146
#ifdef _WIN32
147
const VulkanLogOptions *options = (const VulkanLogOptions *)pUserData;
148
OutputDebugStringA(msg.c_str());
149
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
150
if (options->breakOnError && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT)) {
151
DebugBreak();
152
}
153
if (options->msgBoxOnError) {
154
MessageBoxA(NULL, pMessage, "Alert", MB_OK);
155
}
156
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
157
// Don't break on perf warnings for now, even with a debugger. We log them at least.
158
if (options->breakOnWarning && System_GetPropertyBool(SYSPROP_DEBUGGER_PRESENT) && 0 == (messageType & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)) {
159
DebugBreak();
160
}
161
}
162
#endif
163
164
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
165
ERROR_LOG(Log::G3D, "VKDEBUG: %s", msg.c_str());
166
} else {
167
WARN_LOG(Log::G3D, "VKDEBUG: %s", msg.c_str());
168
}
169
170
// false indicates that layer should not bail-out of an
171
// API call that had validation failures. This may mean that the
172
// app dies inside the driver due to invalid parameter(s).
173
// That's what would happen without validation layers, so we'll
174
// keep that behavior here.
175
return false;
176
}
177
178