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
29 namespace vk
30 {
31
32 namespace
33 {
34
shortDebugFlagsStr(VkDebugReportFlagsEXT flags)35 tcu::Format::Bitfield<32> shortDebugFlagsStr (VkDebugReportFlagsEXT flags)
36 {
37 static const tcu::Format::BitDesc s_bits[] =
38 {
39 tcu::Format::BitDesc(VK_DEBUG_REPORT_INFORMATION_BIT_EXT, "INFO"),
40 tcu::Format::BitDesc(VK_DEBUG_REPORT_WARNING_BIT_EXT, "WARNING"),
41 tcu::Format::BitDesc(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "PERFORMANCE"),
42 tcu::Format::BitDesc(VK_DEBUG_REPORT_ERROR_BIT_EXT, "ERROR"),
43 tcu::Format::BitDesc(VK_DEBUG_REPORT_DEBUG_BIT_EXT, "DEBUG"),
44 };
45
46 return tcu::Format::Bitfield<32>(flags, DE_ARRAY_BEGIN(s_bits), DE_ARRAY_END(s_bits));
47 }
48
getShortObjectTypeName(VkDebugReportObjectTypeEXT objectType)49 const char* getShortObjectTypeName (VkDebugReportObjectTypeEXT objectType)
50 {
51 switch (objectType)
52 {
53 case VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT: return "Unknown";
54 case VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT: return "Instance";
55 case VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT: return "PhysicalDevice";
56 case VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT: return "Device";
57 case VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT: return "Queue";
58 case VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT: return "Semaphore";
59 case VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT: return "CommandBuffer";
60 case VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT: return "Fence";
61 case VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT: return "DeviceMemory";
62 case VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT: return "Buffer";
63 case VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT: return "Image";
64 case VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT: return "Event";
65 case VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT: return "QueryPool";
66 case VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT: return "BufferView";
67 case VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT: return "ImageView";
68 case VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT: return "ShaderModule";
69 case VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT: return "PipelineCache";
70 case VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT: return "PipelineLayout";
71 case VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT: return "RenderPass";
72 case VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT: return "Pipeline";
73 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT: return "DescriptorSetLayout";
74 case VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT: return "Sampler";
75 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT: return "DescriptorPool";
76 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT: return "DescriptorSet";
77 case VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT: return "Framebuffer";
78 case VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT: return "CommandPool";
79 case VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT: return "SurfaceKHR";
80 case VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT: return "SwapchainKHR";
81 case VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT: return "DebugReportEXT";
82 case VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT: return "DisplayKHR";
83 case VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT: return "DisplayModeKHR";
84 case VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR_EXT: return "DescriptorUpdateTemplateKHR";
85 default: return DE_NULL;
86 }
87 }
88
shortObjectTypeStr(VkDebugReportObjectTypeEXT objectType)89 tcu::Format::Enum<VkDebugReportObjectTypeEXT> shortObjectTypeStr (VkDebugReportObjectTypeEXT objectType)
90 {
91 return tcu::Format::Enum<VkDebugReportObjectTypeEXT>(getShortObjectTypeName, objectType);
92 }
93
94 } // anonymous
95
operator <<(std::ostream & str,const DebugReportMessage & message)96 std::ostream& operator<< (std::ostream& str, const DebugReportMessage& message)
97 {
98 str << shortDebugFlagsStr(message.flags) << ": "
99 << message.message
100 << " (code " << tcu::toHex(message.messageCode);
101
102 if (!message.layerPrefix.empty())
103 str << " from " << message.layerPrefix;
104
105 str << " at " << shortObjectTypeStr(message.objectType) << ":" << message.location << ")";
106
107 return str;
108 }
109
110 namespace
111 {
112
debugReportCallback(VkDebugReportFlagsEXT flags,VkDebugReportObjectTypeEXT objectType,deUint64 object,size_t location,deInt32 messageCode,const char * pLayerPrefix,const char * pMessage,void * pUserData)113 VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback (VkDebugReportFlagsEXT flags,
114 VkDebugReportObjectTypeEXT objectType,
115 deUint64 object,
116 size_t location,
117 deInt32 messageCode,
118 const char* pLayerPrefix,
119 const char* pMessage,
120 void* pUserData)
121 {
122 DebugReportRecorder::MessageList* const messageList = reinterpret_cast<DebugReportRecorder::MessageList*>(pUserData);
123
124 messageList->append(DebugReportMessage(flags, objectType, object, location, messageCode, pLayerPrefix, pMessage));
125
126 // Return false to indicate that the call should not return error and should
127 // continue execution normally.
128 return VK_FALSE;
129 }
130
createCallback(const InstanceInterface & vki,VkInstance instance,DebugReportRecorder::MessageList * messageList)131 Move<VkDebugReportCallbackEXT> createCallback (const InstanceInterface& vki,
132 VkInstance instance,
133 DebugReportRecorder::MessageList* messageList)
134 {
135 const VkDebugReportFlagsEXT allFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT
136 | VK_DEBUG_REPORT_WARNING_BIT_EXT
137 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT
138 | VK_DEBUG_REPORT_ERROR_BIT_EXT
139 | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
140
141 const VkDebugReportCallbackCreateInfoEXT createInfo =
142 {
143 VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
144 DE_NULL,
145 allFlags,
146 debugReportCallback,
147 messageList
148 };
149
150 return createDebugReportCallbackEXT(vki, instance, &createInfo);
151 }
152
153 } // anonymous
154
DebugReportRecorder(const InstanceInterface & vki,VkInstance instance)155 DebugReportRecorder::DebugReportRecorder (const InstanceInterface& vki, VkInstance instance)
156 : m_messages (1024)
157 , m_callback (createCallback(vki, instance, &m_messages))
158 {
159 }
160
~DebugReportRecorder(void)161 DebugReportRecorder::~DebugReportRecorder (void)
162 {
163 }
164
isDebugReportSupported(const PlatformInterface & vkp)165 bool isDebugReportSupported (const PlatformInterface& vkp)
166 {
167 return isExtensionSupported(enumerateInstanceExtensionProperties(vkp, DE_NULL),
168 RequiredExtension("VK_EXT_debug_report"));
169 }
170
171 } // vk
172