1 /*-------------------------------------------------------------------------
2 * Vulkan CTS Framework
3 * --------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief VK_EXT_debug_report utilities
22 *//*--------------------------------------------------------------------*/
23
24 #include "vkDebugReportUtil.hpp"
25 #include "vkRefUtil.hpp"
26 #include "vkQueryUtil.hpp"
27 #include "deArrayUtil.hpp"
28 #include "tcuDefs.hpp"
29
30 namespace vk
31 {
32
33 namespace
34 {
35
shortDebugFlagsStr(VkDebugReportFlagsEXT flags)36 tcu::Format::Bitfield<32> shortDebugFlagsStr (VkDebugReportFlagsEXT flags)
37 {
38 static const tcu::Format::BitDesc s_bits[] =
39 {
40 tcu::Format::BitDesc(VK_DEBUG_REPORT_INFORMATION_BIT_EXT, "INFO"),
41 tcu::Format::BitDesc(VK_DEBUG_REPORT_WARNING_BIT_EXT, "WARNING"),
42 tcu::Format::BitDesc(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "PERFORMANCE"),
43 tcu::Format::BitDesc(VK_DEBUG_REPORT_ERROR_BIT_EXT, "ERROR"),
44 tcu::Format::BitDesc(VK_DEBUG_REPORT_DEBUG_BIT_EXT, "DEBUG"),
45 };
46
47 return tcu::Format::Bitfield<32>(flags, DE_ARRAY_BEGIN(s_bits), DE_ARRAY_END(s_bits));
48 }
49
getShortObjectTypeName(VkDebugReportObjectTypeEXT objectType)50 const char* getShortObjectTypeName (VkDebugReportObjectTypeEXT objectType)
51 {
52 switch (objectType)
53 {
54 case VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT: return "Unknown";
55 case VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT: return "Instance";
56 case VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT: return "PhysicalDevice";
57 case VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT: return "Device";
58 case VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT: return "Queue";
59 case VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT: return "Semaphore";
60 case VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT: return "CommandBuffer";
61 case VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT: return "Fence";
62 case VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT: return "DeviceMemory";
63 case VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT: return "Buffer";
64 case VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT: return "Image";
65 case VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT: return "Event";
66 case VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT: return "QueryPool";
67 case VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT: return "BufferView";
68 case VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT: return "ImageView";
69 case VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT: return "ShaderModule";
70 case VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT: return "PipelineCache";
71 case VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT: return "PipelineLayout";
72 case VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT: return "RenderPass";
73 case VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT: return "Pipeline";
74 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT: return "DescriptorSetLayout";
75 case VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT: return "Sampler";
76 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT: return "DescriptorPool";
77 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT: return "DescriptorSet";
78 case VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT: return "Framebuffer";
79 case VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT: return "CommandPool";
80 case VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT: return "SurfaceKHR";
81 case VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT: return "SwapchainKHR";
82 case VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT: return "DebugReportEXT";
83 case VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT: return "DisplayKHR";
84 case VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT: return "DisplayModeKHR";
85 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR_EXT: return "DescriptorUpdateTemplateKHR";
86 default: return DE_NULL;
87 }
88 }
89
shortObjectTypeStr(VkDebugReportObjectTypeEXT objectType)90 tcu::Format::Enum<VkDebugReportObjectTypeEXT> shortObjectTypeStr (VkDebugReportObjectTypeEXT objectType)
91 {
92 return tcu::Format::Enum<VkDebugReportObjectTypeEXT>(getShortObjectTypeName, objectType);
93 }
94
95 } // anonymous
96
operator <<(std::ostream & str,const DebugReportMessage & message)97 std::ostream& operator<< (std::ostream& str, const DebugReportMessage& message)
98 {
99 str << shortDebugFlagsStr(message.flags) << ": "
100 << message.message
101 << " (code " << tcu::toHex(message.messageCode);
102
103 if (!message.layerPrefix.empty())
104 str << " from " << message.layerPrefix;
105
106 str << " at " << shortObjectTypeStr(message.objectType) << ":" << message.location << ")";
107
108 return str;
109 }
110
111 namespace
112 {
113
debugReportCallback(VkDebugReportFlagsEXT flags,VkDebugReportObjectTypeEXT objectType,deUint64 object,size_t location,deInt32 messageCode,const char * pLayerPrefix,const char * pMessage,void * pUserData)114 VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback (VkDebugReportFlagsEXT flags,
115 VkDebugReportObjectTypeEXT objectType,
116 deUint64 object,
117 size_t location,
118 deInt32 messageCode,
119 const char* pLayerPrefix,
120 const char* pMessage,
121 void* pUserData)
122 {
123 auto recorder = reinterpret_cast<DebugReportRecorder*>(pUserData);
124 auto& messageList = recorder->getMessages();
125 const DebugReportMessage message (flags, objectType, object, location, messageCode, pLayerPrefix, pMessage);
126
127 messageList.append(message);
128
129 if (recorder->errorPrinting() && message.isError())
130 tcu::printError("%s\n", pMessage);
131
132 // Return false to indicate that the call should not return error and should
133 // continue execution normally.
134 return VK_FALSE;
135 }
136
137 } // anonymous
138
DebugReportRecorder(bool printValidationErrors)139 DebugReportRecorder::DebugReportRecorder (bool printValidationErrors)
140 : m_messages (1024)
141 , m_print_errors (printValidationErrors)
142 {
143 }
144
~DebugReportRecorder(void)145 DebugReportRecorder::~DebugReportRecorder (void)
146 {
147 }
148
makeCreateInfo(void)149 VkDebugReportCallbackCreateInfoEXT DebugReportRecorder::makeCreateInfo (void)
150 {
151 const VkDebugReportFlagsEXT allFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT
152 | VK_DEBUG_REPORT_WARNING_BIT_EXT
153 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT
154 | VK_DEBUG_REPORT_ERROR_BIT_EXT
155 | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
156
157 const VkDebugReportCallbackCreateInfoEXT createInfo =
158 {
159 VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
160 nullptr,
161 allFlags,
162 debugReportCallback,
163 this,
164 };
165
166 return createInfo;
167 }
168
createCallback(const InstanceInterface & vki,VkInstance instance)169 Move<VkDebugReportCallbackEXT> DebugReportRecorder::createCallback (const InstanceInterface& vki, VkInstance instance)
170 {
171 const auto createInfo = makeCreateInfo();
172 return createDebugReportCallbackEXT(vki, instance, &createInfo);
173 }
174
isDebugReportSupported(const PlatformInterface & vkp)175 bool isDebugReportSupported (const PlatformInterface& vkp)
176 {
177 return isExtensionSupported(enumerateInstanceExtensionProperties(vkp, DE_NULL),
178 RequiredExtension("VK_EXT_debug_report"));
179 }
180
181 } // vk
182