| Flutter Impeller |

debug_report_vk.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
5 #include "impeller/renderer/backend/vulkan/debug_report_vk.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/renderer/backend/vulkan/capabilities_vk.h"
9
10 namespace impeller {
11
12 DebugReportVK::DebugReportVK(const CapabilitiesVK& caps,
13 const vk::Instance& instance) {
14 if (!caps.AreValidationsEnabled()) {
15 is_valid_ = true;
16 return;
17 }
18
19 vk::DebugUtilsMessengerCreateInfoEXT messenger_info;
20 messenger_info.messageSeverity =
21 vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
22 vk::DebugUtilsMessageSeverityFlagBitsEXT::eError;
23 messenger_info.messageType =
24 vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
25 vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
26 vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation;
27 messenger_info.pUserData = this;
28 messenger_info.pfnUserCallback = DebugUtilsMessengerCallback;
29
30 auto messenger = instance.createDebugUtilsMessengerEXTUnique(messenger_info);
31
32 if (messenger.result != vk::Result::eSuccess) {
33 FML_LOG(ERROR) << "Could not create debug messenger: "
34 << vk::to_string(messenger.result);
35 return;
36 }
37
38 messenger_ = std::move(messenger.value);
39 is_valid_ = true;
40 }
41
42 DebugReportVK::~DebugReportVK() = default;
43
44 bool DebugReportVK::IsValid() const {
45 return is_valid_;
46 }
47
48 static std::string JoinLabels(const VkDebugUtilsLabelEXT* labels,
49 size_t count) {
50 std::stringstream stream;
51 for (size_t i = 0u; i < count; i++) {
52 stream << labels[i].pLabelName;
53 if (i != count - 1u) {
54 stream << ", ";
55 }
56 }
57 return stream.str();
58 }
59
60 static std::string JoinVKDebugUtilsObjectNameInfoEXT(
61 const VkDebugUtilsObjectNameInfoEXT* names,
62 size_t count) {
63 std::stringstream stream;
64 for (size_t i = 0u; i < count; i++) {
65 stream << vk::to_string(static_cast<vk::ObjectType>(names[i].objectType))
66 << " [" << names[i].objectHandle << "] [";
67 if (names[i].pObjectName != nullptr) {
68 stream << names[i].pObjectName;
69 } else {
70 stream << "UNNAMED";
71 }
72 stream << "]";
73 if (i != count - 1u) {
74 stream << ", ";
75 }
76 }
77 return stream.str();
78 }
79
80 VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportVK::DebugUtilsMessengerCallback(
81 VkDebugUtilsMessageSeverityFlagBitsEXT severity,
82 VkDebugUtilsMessageTypeFlagsEXT type,
83 const VkDebugUtilsMessengerCallbackDataEXT* callback_data,
84 void* debug_report) {
85 auto result =
86 reinterpret_cast<DebugReportVK*>(debug_report)
87 ->OnDebugCallback(
88 static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(
89 severity), //
90 static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(type), //
91 callback_data //
92 );
93 switch (result) {
94 case Result::kContinue:
95 return VK_FALSE;
96 case Result::kAbort:
97 return VK_TRUE;
98 }
99 return VK_FALSE;
100 }
101
102 DebugReportVK::Result DebugReportVK::OnDebugCallback(
103 vk::DebugUtilsMessageSeverityFlagBitsEXT severity,
104 vk::DebugUtilsMessageTypeFlagsEXT type,
105 const VkDebugUtilsMessengerCallbackDataEXT* data) {
106 // This is a real issue caused by INPUT_ATTACHMENT_BIT not being a supported
107 // `VkSurfaceCapabilitiesKHR::supportedUsageFlags` on any platform other than
108 // Android. This is necessary for all the framebuffer fetch related tests. We
109 // can get away with suppressing this on macOS but this must be fixed.
110 if (data->messageIdNumber == 0x2c36905d) {
111 return Result::kContinue;
112 }
113 // This is a performance warning when a fragment stage does not consume all
114 // varyings from the vertex stage. We ignore this as we want to use a single
115 // vertex stage for the runtime effect shader without trying to determine if
116 // the fragment consumes it or not.
117 if (data->messageIdNumber == 0x609A13B) {
118 return Result::kContinue;
119 }
120 // TODO(149111): Fix VUID-VkShaderModuleCreateInfo-pCode-08737.
121 if (data->pMessageIdName != nullptr &&
122 strcmp(data->pMessageIdName,
123 "VUID-VkShaderModuleCreateInfo-pCode-08737") == 0) {
124 return Result::kContinue;
125 }
126 // TODO(149111): Fix
127 // VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849.
128 if (data->pMessageIdName != nullptr &&
129 strcmp(
130 data->pMessageIdName,
131 "VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849") ==
132 0) {
133 return Result::kContinue;
134 }
135
136 std::vector<std::pair<std::string, std::string>> items;
137
138 items.emplace_back("Severity", vk::to_string(severity));
139
140 items.emplace_back("Type", vk::to_string(type));
141
142 if (data->pMessageIdName) {
143 items.emplace_back("ID Name", data->pMessageIdName);
144 }
145
146 items.emplace_back("ID Number", std::to_string(data->messageIdNumber));
147
148 if (auto queues = JoinLabels(data->pQueueLabels, data->queueLabelCount);
149 !queues.empty()) {
150 items.emplace_back("Queue Breadcrumbs", std::move(queues));
151 } else {
152 items.emplace_back("Queue Breadcrumbs", "[NONE]");
153 }
154
155 if (auto cmd_bufs = JoinLabels(data->pCmdBufLabels, data->cmdBufLabelCount);
156 !cmd_bufs.empty()) {
157 items.emplace_back("CMD Buffer Breadcrumbs", std::move(cmd_bufs));
158 } else {
159 items.emplace_back("CMD Buffer Breadcrumbs", "[NONE]");
160 }
161
162 if (auto related =
163 JoinVKDebugUtilsObjectNameInfoEXT(data->pObjects, data->objectCount);
164 !related.empty()) {
165 items.emplace_back("Related Objects", std::move(related));
166 }
167
168 if (data->pMessage) {
169 items.emplace_back("Trigger", data->pMessage);
170 }
171
172 size_t padding = 0;
173
174 for (const auto& item : items) {
175 padding = std::max(padding, item.first.size());
176 }
177
178 padding += 1;
179
180 std::stringstream stream;
181
182 stream << std::endl;
183
184 stream << "--- Vulkan Debug Report ----------------------------------------";
185
186 stream << std::endl;
187
188 for (const auto& item : items) {
189 stream << "| " << std::setw(static_cast<int>(padding)) << item.first
190 << std::setw(0) << ": " << item.second << std::endl;
191 }
192
193 stream << "-----------------------------------------------------------------";
194
195 if (type == vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance) {
196 FML_LOG(INFO) << stream.str();
197 } else {
198 VALIDATION_LOG << stream.str();
199 }
200
201 return Result::kContinue;
202 }
203
204 } // namespace impeller
type
GLenum type
Definition: blit_command_gles.cc:151
capabilities_vk.h
impeller::CapabilitiesVK
The Vulkan layers and extensions wrangler.
Definition: capabilities_vk.h:171
impeller::CapabilitiesVK::AreValidationsEnabled
bool AreValidationsEnabled() const
Definition: capabilities_vk.cc:79
impeller::DebugReportVK::DebugReportVK
DebugReportVK(const CapabilitiesVK &caps, const vk::Instance &instance)
Definition: debug_report_vk.cc:12
impeller::DebugReportVK::IsValid
bool IsValid() const
Definition: debug_report_vk.cc:44
impeller::DebugReportVK::~DebugReportVK
~DebugReportVK()
debug_report_vk.h
padding
Vector2 padding
The halo padding in source space.
Definition: gaussian_blur_filter_contents.cc:86
impeller
Definition: allocation.cc:12
impeller::JoinVKDebugUtilsObjectNameInfoEXT
static std::string JoinVKDebugUtilsObjectNameInfoEXT(const VkDebugUtilsObjectNameInfoEXT *names, size_t count)
Definition: debug_report_vk.cc:60
impeller::JoinLabels
static std::string JoinLabels(const VkDebugUtilsLabelEXT *labels, size_t count)
Definition: debug_report_vk.cc:48
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:64
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91