Flutter Engine
The Flutter Engine
vulkan_debug_report.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <algorithm>
8#include <iomanip>
9#include <vector>
10
11#include "flutter/fml/compiler_specific.h"
12#include "vulkan_utilities.h"
13
14namespace vulkan {
15
16static const VkDebugReportFlagsEXT kVulkanErrorFlags FML_ALLOW_UNUSED_TYPE =
19
20static const VkDebugReportFlagsEXT kVulkanInfoFlags FML_ALLOW_UNUSED_TYPE =
22
25}
26
29 return "Information";
31 return "Warning";
33 return "Performance Warning";
35 return "Error";
37 return "Debug";
38 }
39 return "UNKNOWN";
40}
41
44 switch (type) {
46 return "Unknown";
48 return "Instance";
50 return "Physical Device";
52 return "Device";
54 return "Queue";
56 return "Semaphore";
58 return "Command Buffer";
60 return "Fence";
62 return "Device Memory";
64 return "Buffer";
66 return "Image";
68 return "Event";
70 return "Query Pool";
72 return "Buffer View";
74 return "Image_view";
76 return "Shader Module";
78 return "Pipeline Cache";
80 return "Pipeline Layout";
82 return "Render Pass";
84 return "Pipeline";
86 return "Descriptor Set Layout";
88 return "Sampler";
90 return "Descriptor Pool";
92 return "Descriptor Set";
94 return "Framebuffer";
96 return "Command Pool";
98 return "Surface";
100 return "Swapchain";
102 return "Debug";
103 default:
104 break;
105 }
106
107 return "Unknown";
108}
109
110static VKAPI_ATTR VkBool32
111#ifdef WIN32
112 __stdcall
113#endif
115 VkDebugReportObjectTypeEXT object_type,
116 uint64_t object,
117 size_t location,
118 int32_t message_code,
119 const char* layer_prefix,
120 const char* message,
121 void* user_data) {
122 std::vector<std::pair<std::string, std::string>> items;
123
124 items.emplace_back("Severity", VkDebugReportFlagsEXTToString(flags));
125
126 items.emplace_back("Object Type",
128
129 items.emplace_back("Object Handle", std::to_string(object));
130
131 if (location != 0) {
132 items.emplace_back("Location", std::to_string(location));
133 }
134
135 if (message_code != 0) {
136 items.emplace_back("Message Code", std::to_string(message_code));
137 }
138
139 if (layer_prefix != nullptr) {
140 items.emplace_back("Layer", layer_prefix);
141 }
142
143 if (message != nullptr) {
144 items.emplace_back("Message", message);
145 }
146
147 size_t padding = 0;
148
149 for (const auto& item : items) {
150 padding = std::max(padding, item.first.size());
151 }
152
153 padding += 1;
154
155 std::stringstream stream;
156
157 stream << std::endl;
158
159 stream << "--- Vulkan Debug Report ----------------------------------------";
160
161 stream << std::endl;
162
163 for (const auto& item : items) {
164 stream << "| " << std::setw(static_cast<int>(padding)) << item.first
165 << std::setw(0) << ": " << item.second << std::endl;
166 }
167
168 stream << "-----------------------------------------------------------------";
169
170 if (flags & kVulkanErrorFlags) {
171 if (ValidationErrorsFatal()) {
172 FML_DCHECK(false) << stream.str();
173 } else {
174 FML_LOG(ERROR) << stream.str();
175 }
176 } else {
177 FML_LOG(INFO) << stream.str();
178 }
179
180 // Returning false tells the layer not to stop when the event occurs, so
181 // they see the same behavior with and without validation layers enabled.
182 return VK_FALSE;
183}
184
186 const VulkanProcTable& p_vk,
187 const VulkanHandle<VkInstance>& application)
188 : vk_(p_vk), application_(application), valid_(false) {
189 if (!vk_.CreateDebugReportCallbackEXT || !vk_.DestroyDebugReportCallbackEXT) {
190 return;
191 }
192
193 if (!application_) {
194 return;
195 }
196
197 VkDebugReportFlagsEXT flags = kVulkanErrorFlags;
199 flags |= kVulkanInfoFlags;
200 }
201 const VkDebugReportCallbackCreateInfoEXT create_info = {
203 .pNext = nullptr,
204 .flags = flags,
206 .pUserData = nullptr,
207 };
208
209 VkDebugReportCallbackEXT handle = VK_NULL_HANDLE;
210 if (VK_CALL_LOG_ERROR(vk_.CreateDebugReportCallbackEXT(
211 application_, &create_info, nullptr, &handle)) != VK_SUCCESS) {
212 return;
213 }
214
216 handle, [this](VkDebugReportCallbackEXT handle) {
217 vk_.DestroyDebugReportCallbackEXT(application_, handle, nullptr);
218 }};
219
220 valid_ = true;
221}
222
224
226 return valid_;
227}
228
229} // namespace vulkan
GLenum type
VulkanDebugReport(const VulkanProcTable &vk, const VulkanHandle< VkInstance > &application)
static std::string DebugExtensionName()
FlutterSemanticsFlag flags
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
static float max(float r, float g, float b)
Definition: hsl.cpp:49
Win32Message message
bool ValidationErrorsFatal()
static const char * VkDebugReportFlagsEXTToString(VkDebugReportFlagsEXT flags)
static VKAPI_ATTR VkBool32 OnVulkanDebugReportCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT object_type, uint64_t object, size_t location, int32_t message_code, const char *layer_prefix, const char *message, void *user_data)
static const VkDebugReportFlagsEXT kVulkanErrorFlags FML_ALLOW_UNUSED_TYPE
static const char * VkDebugReportObjectTypeEXTToString(VkDebugReportObjectTypeEXT type)
bool ValidationLayerInfoMessagesEnabled()
static SkString to_string(int n)
Definition: nanobench.cpp:119
void * user_data
#define ERROR(message)
Definition: elf_loader.cc:260
#define VKAPI_ATTR
Definition: vk_platform.h:56
@ VK_DEBUG_REPORT_INFORMATION_BIT_EXT
@ VK_DEBUG_REPORT_WARNING_BIT_EXT
@ VK_DEBUG_REPORT_DEBUG_BIT_EXT
@ VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT
@ VK_DEBUG_REPORT_ERROR_BIT_EXT
VkDebugReportObjectTypeEXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT
@ VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT
#define VK_EXT_DEBUG_REPORT_EXTENSION_NAME
#define VK_FALSE
Definition: vulkan_core.h:125
@ VK_SUCCESS
Definition: vulkan_core.h:141
VkFlags VkDebugReportFlagsEXT
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
uint32_t VkBool32
Definition: vulkan_core.h:94
@ VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT
Definition: vulkan_core.h:1148
#define VK_CALL_LOG_ERROR(expression)