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