Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 95ad929

Browse files
author
John Bauman
committed
Log Vulkan loader errors if the instance failed creation on Fuchsia
1 parent 8eba63f commit 95ad929

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

vulkan/vulkan_application.cc

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@
1313

1414
namespace vulkan {
1515

16+
class InitializationDebugReporter {
17+
public:
18+
static VKAPI_ATTR VkBool32
19+
DebugReportCallback(VkDebugReportFlagsEXT flags,
20+
VkDebugReportObjectTypeEXT objectType,
21+
uint64_t object,
22+
size_t location,
23+
int32_t messageCode,
24+
const char* pLayerPrefix,
25+
const char* pMessage,
26+
void* pUserData) {
27+
auto reporter = static_cast<InitializationDebugReporter*>(pUserData);
28+
29+
reporter->logs_ += pMessage;
30+
reporter->logs_ += "\n";
31+
return VK_FALSE;
32+
}
33+
34+
const std::string logs() const { return logs_; }
35+
36+
private:
37+
std::string logs_;
38+
};
39+
1640
VulkanApplication::VulkanApplication(
1741
VulkanProcTable& p_vk, // NOLINT
1842
const std::string& application_name,
@@ -79,9 +103,19 @@ VulkanApplication::VulkanApplication(
79103
.apiVersion = api_version_,
80104
};
81105

106+
InitializationDebugReporter reporter;
107+
const VkDebugReportCallbackCreateInfoEXT debug_report_info = {
108+
.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
109+
.pNext = nullptr,
110+
.flags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT |
111+
VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT |
112+
VK_DEBUG_REPORT_DEBUG_BIT_EXT,
113+
.pfnCallback = &InitializationDebugReporter::DebugReportCallback,
114+
.pUserData = &reporter};
115+
82116
const VkInstanceCreateInfo create_info = {
83117
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
84-
.pNext = nullptr,
118+
.pNext = &debug_report_info,
85119
.flags = 0,
86120
.pApplicationInfo = &info,
87121
.enabledLayerCount = static_cast<uint32_t>(layers.size()),
@@ -96,6 +130,9 @@ VulkanApplication::VulkanApplication(
96130

97131
if (VK_CALL_LOG_ERROR(vk_.CreateInstance(&create_info, nullptr, &instance)) !=
98132
VK_SUCCESS) {
133+
#if OS_FUCHSIA
134+
FML_LOG(ERROR) << "Creating instance failed with error:\n" << reporter.logs();
135+
#endif
99136
FML_DLOG(INFO) << "Could not create application instance.";
100137
return;
101138
}

0 commit comments

Comments
 (0)