| 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 vk::DebugUtilsLabelEXT* 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 vk::DebugUtilsObjectNameInfoEXT* 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 vk::DebugUtilsMessageSeverityFlagBitsEXT severity,
82 vk::DebugUtilsMessageTypeFlagsEXT type,
83 const vk::DebugUtilsMessengerCallbackDataEXT* 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 vk::DebugUtilsMessengerCallbackDataEXT* 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
121 // This warning happens when running tests that use SwiftShader.
122 // Some SPIR-V shaders request the UniformAndStorageBuffer16BitAccess
123 // capability, but SwiftShader does not support it.
124 if (data->pMessageIdName != nullptr &&
125 strcmp(data->pMessageIdName,
126 "VUID-VkShaderModuleCreateInfo-pCode-08740") == 0) {
127 return Result::kContinue;
128 }
129
130 std::vector<std::pair<std::string, std::string>> items;
131
132 items.emplace_back("Severity", vk::to_string(severity));
133 items.emplace_back("Type", vk::to_string(type));
134
135 if (data->pMessageIdName) {
136 items.emplace_back("ID Name", data->pMessageIdName);
137 }
138
139 items.emplace_back("ID Number", std::to_string(data->messageIdNumber));
140
141 if (auto queues = JoinLabels(data->pQueueLabels, data->queueLabelCount);
142 !queues.empty()) {
143 items.emplace_back("Queue Breadcrumbs", std::move(queues));
144 } else {
145 items.emplace_back("Queue Breadcrumbs", "[NONE]");
146 }
147
148 if (auto cmd_bufs = JoinLabels(data->pCmdBufLabels, data->cmdBufLabelCount);
149 !cmd_bufs.empty()) {
150 items.emplace_back("CMD Buffer Breadcrumbs", std::move(cmd_bufs));
151 } else {
152 items.emplace_back("CMD Buffer Breadcrumbs", "[NONE]");
153 }
154
155 if (auto related =
156 JoinVKDebugUtilsObjectNameInfoEXT(data->pObjects, data->objectCount);
157 !related.empty()) {
158 items.emplace_back("Related Objects", std::move(related));
159 }
160
161 if (data->pMessage) {
162 items.emplace_back("Trigger", data->pMessage);
163 }
164
165 size_t padding = 0;
166
167 for (const auto& item : items) {
168 padding = std::max(padding, item.first.size());
169 }
170
171 padding += 1;
172
173 std::stringstream stream;
174
175 stream << std::endl;
176
177 stream << "--- Vulkan Debug Report ----------------------------------------";
178
179 stream << std::endl;
180
181 for (const auto& item : items) {
182 stream << "| " << std::setw(static_cast<int>(padding)) << item.first
183 << std::setw(0) << ": " << item.second << std::endl;
184 }
185
186 stream << "-----------------------------------------------------------------";
187
188 if (type == vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance) {
189 FML_LOG(INFO) << stream.str();
190 } else {
191 VALIDATION_LOG << stream.str();
192 }
193
194 return Result::kContinue;
195 }
196
197 } // namespace impeller
type
GLenum type
Definition: blit_command_gles.cc:153
capabilities_vk.h
impeller::CapabilitiesVK
The Vulkan layers and extensions wrangler.
Definition: capabilities_vk.h:181
impeller::CapabilitiesVK::AreValidationsEnabled
bool AreValidationsEnabled() const
Definition: capabilities_vk.cc:82
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 vk::DebugUtilsObjectNameInfoEXT *names, size_t count)
Definition: debug_report_vk.cc:60
impeller::JoinLabels
static std::string JoinLabels(const vk::DebugUtilsLabelEXT *labels, size_t count)
Definition: debug_report_vk.cc:48
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:68
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91