• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKDEFS_HPP
2 #define _VKDEFS_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2015 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Vulkan utilites.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 
28 #if (DE_OS == DE_OS_ANDROID) && defined(__ARM_ARCH) && defined(__ARM_32BIT_STATE)
29 #	define VKAPI_ATTR __attribute__((pcs("aapcs-vfp")))
30 #else
31 #	define VKAPI_ATTR
32 #endif
33 
34 #if (DE_OS == DE_OS_WIN32) && ((defined(_MSC_VER) && _MSC_VER >= 800) || defined(__MINGW32__) || defined(_STDCALL_SUPPORTED))
35 #	define VKAPI_CALL __stdcall
36 #else
37 #	define VKAPI_CALL
38 #endif
39 
40 #define VK_NULL_HANDLE									DE_NULL
41 #define VK_DEFINE_HANDLE(NAME, TYPE)					typedef struct NAME##_s* NAME
42 #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(NAME, TYPE)	typedef Handle<TYPE> NAME
43 
44 #define VK_DEFINE_PLATFORM_TYPE(NAME, COMPATIBLE)		\
45 namespace pt {											\
46 struct NAME {											\
47 	COMPATIBLE internal;								\
48 	explicit NAME (COMPATIBLE internal_)				\
49 		: internal(internal_) {}						\
50 };														\
51 } // pt
52 
53 #define VK_MAKE_API_VERSION(VARIANT, MAJOR, MINOR, PATCH)	\
54 												((((deUint32)(VARIANT)) << 29) | (((deUint32)(MAJOR)) << 22) | (((deUint32)(MINOR)) << 12) | ((deUint32)(PATCH)))
55 #define VKSC_API_VARIANT						1
56 #define VK_MAKE_VERSION(MAJOR, MINOR, PATCH)	VK_MAKE_API_VERSION(0, MAJOR, MINOR, PATCH)
57 #define VK_BIT(NUM)								(1u<<(deUint32)(NUM))
58 
59 #define VK_API_VERSION_VARIANT(version)			((deUint32)(version) >> 29)
60 #define VK_API_VERSION_MAJOR(version)			(((deUint32)(version) >> 22) & 0x7FU)
61 #define VK_API_VERSION_MINOR(version)			(((deUint32)(version) >> 12) & 0x3FFU)
62 #define VK_API_VERSION_PATCH(version)			((deUint32)(version) & 0xFFFU)
63 
64 #define VK_CHECK(EXPR)							vk::checkResult((EXPR), #EXPR, __FILE__, __LINE__)
65 #define VK_CHECK_SUPPORTED(EXPR)				vk::checkResultSupported((EXPR), #EXPR, __FILE__, __LINE__)
66 #define VK_CHECK_MSG(EXPR, MSG)					vk::checkResult((EXPR), MSG, __FILE__, __LINE__)
67 #define VK_CHECK_WSI(EXPR)						vk::checkWsiResult((EXPR), #EXPR, __FILE__, __LINE__)
68 
69 #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \
70     ((((deUint32)(major)) << 22) | (((deUint32)(minor)) << 12) | ((deUint32)(patch)))
71 
72 /*--------------------------------------------------------------------*//*!
73  * \brief Vulkan utilities
74  *//*--------------------------------------------------------------------*/
75 namespace vk
76 {
77 
78 typedef deUint64	VkDeviceSize;
79 typedef deUint32	VkSampleMask;
80 typedef deUint32	VkBool32;
81 typedef deUint32	VkFlags;
82 typedef deUint64	VkFlags64;
83 typedef deUint64	VkDeviceAddress;
84 
85 // enum HandleType { HANDLE_TYPE_INSTANCE, ... };
86 #include "vkHandleType.inl"
87 
88 template<HandleType Type>
89 class Handle
90 {
91 public:
Handle(void)92 				Handle		(void) {} // \note Left uninitialized on purpose
Handle(deUint64 internal)93 				Handle		(deUint64 internal) : m_internal(internal) {}
94 
operator =(deUint64 internal)95 	Handle&		operator=	(deUint64 internal)					{ m_internal = internal; return *this;			}
96 
operator ==(const Handle<Type> & other) const97 	bool		operator==	(const Handle<Type>& other) const	{ return this->m_internal == other.m_internal;	}
operator !=(const Handle<Type> & other) const98 	bool		operator!=	(const Handle<Type>& other) const	{ return this->m_internal != other.m_internal;	}
99 
operator !(void) const100 	bool		operator!	(void) const						{ return !m_internal;							}
101 
getInternal(void) const102 	deUint64	getInternal	(void) const						{ return m_internal;							}
103 
104 	enum { HANDLE_TYPE = Type };
105 
106 private:
107 	deUint64	m_internal;
108 };
109 
110 template<HandleType Type>
operator <(const Handle<Type> & lhs,const Handle<Type> & rhs)111 bool operator<(const Handle<Type>& lhs, const Handle<Type>& rhs)
112 {
113 	return lhs.getInternal() < rhs.getInternal();
114 }
115 
116 #include "vkBasicTypes.inl"
117 
118 #define VK_CORE_FORMAT_LAST			((vk::VkFormat)(vk::VK_FORMAT_ASTC_12x12_SRGB_BLOCK+1))
119 #define VK_CORE_IMAGE_TILING_LAST	((vk::VkImageTiling)(vk::VK_IMAGE_TILING_LINEAR+1))
120 #define VK_CORE_IMAGE_TYPE_LAST		((vk::VkImageType)(vk::VK_IMAGE_TYPE_3D+1))
121 
122 enum SpirvVersion
123 {
124 	SPIRV_VERSION_1_0	= 0,	//!< SPIR-V 1.0
125 	SPIRV_VERSION_1_1	= 1,	//!< SPIR-V 1.1
126 	SPIRV_VERSION_1_2	= 2,	//!< SPIR-V 1.2
127 	SPIRV_VERSION_1_3	= 3,	//!< SPIR-V 1.3
128 	SPIRV_VERSION_1_4	= 4,	//!< SPIR-V 1.4
129 	SPIRV_VERSION_1_5	= 5,	//!< SPIR-V 1.5
130 	SPIRV_VERSION_1_6	= 6,	//!< SPIR-V 1.6
131 
132 	SPIRV_VERSION_LAST
133 };
134 
135 typedef struct
136 {
137 	deUint32	magic;
138 	deUint32	version;
139 	deUint32	generator;
140 	deUint32	bound;
141 } SpirvBinaryHeader;
142 
143 namespace wsi
144 {
145 
146 enum Type
147 {
148 	TYPE_XLIB = 0,
149 	TYPE_XCB,
150 	TYPE_WAYLAND,
151 	TYPE_ANDROID,
152 	TYPE_WIN32,
153 	TYPE_MACOS,
154 	TYPE_HEADLESS,
155 	TYPE_DIRECT_DRM,
156 	TYPE_OHOS,
157 
158 	TYPE_LAST
159 };
160 
161 } // wsi
162 
163 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkVoidFunction)					(void);
164 
165 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkAllocationFunction)				(void*						pUserData,
166 																				 size_t						size,
167 																				 size_t						alignment,
168 																				 VkSystemAllocationScope	allocationScope);
169 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkReallocationFunction)			(void*						pUserData,
170 																				 void*						pOriginal,
171 																				 size_t						size,
172 																				 size_t						alignment,
173 																				 VkSystemAllocationScope	allocationScope);
174 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkFreeFunction)					(void*						pUserData,
175 																				 void*						pMem);
176 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalAllocationNotification)	(void*						pUserData,
177 																				 size_t						size,
178 																				 VkInternalAllocationType	allocationType,
179 																				 VkSystemAllocationScope	allocationScope);
180 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalFreeNotification)		(void*						pUserData,
181 																				 size_t						size,
182 																				 VkInternalAllocationType	allocationType,
183 																				 VkSystemAllocationScope	allocationScope);
184 
185 #ifndef CTS_USES_VULKANSC
186 
187 typedef VKAPI_ATTR VkBool32	(VKAPI_CALL* PFN_vkDebugReportCallbackEXT)			(VkDebugReportFlagsEXT		flags,
188 																				 VkDebugReportObjectTypeEXT	objectType,
189 																				 deUint64					object,
190 																				 size_t						location,
191 																				 deInt32					messageCode,
192 																				 const char*				pLayerPrefix,
193 																				 const char*				pMessage,
194 																				 void*						pUserData);
195 
196 typedef VKAPI_ATTR PFN_vkVoidFunction (VKAPI_CALL* PFN_vkGetInstanceProcAddrLUNARG)	(VkInstance instance, const char pName);
197 
198 #endif // CTS_USES_VULKANSC
199 
200 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT)	(VkDebugUtilsMessageSeverityFlagBitsEXT				messageSeverity,
201 																				 VkDebugUtilsMessageTypeFlagsEXT					messageTypes,
202 																				 const struct VkDebugUtilsMessengerCallbackDataEXT*	pCallbackData,
203 																				 void*												pUserData);
204 
205 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkDeviceMemoryReportCallbackEXT)	(const struct VkDeviceMemoryReportCallbackDataEXT*	pCallbackData,
206 																				 void*												pUserData);
207 
208 #ifdef CTS_USES_VULKANSC
209 struct VkFaultData;
210 typedef VKAPI_ATTR void		(VKAPI_CALL *PFN_vkFaultCallbackFunction)			(VkBool32											incompleteFaultData,
211 																				 deUint32											faultCount,
212 																				 VkFaultData*										pFaultData);
213 #endif // CTS_USES_VULKANSC
214 
215 #include "vkStructTypes.inl"
216 
217 #ifdef CTS_USES_VULKANSC
218 
219 // substitute required enums and structs removed from VulkanSC specification
220 
221 enum VkShaderModuleCreateFlagBits
222 {
223 	VK_SHADER_MODULE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF,
224 };
225 typedef deUint32 VkShaderModuleCreateFlags;
226 
227 #define VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO VkStructureType(16)
228 #define VK_OBJECT_TYPE_SHADER_MODULE VkObjectType(15)
229 
230 struct VkShaderModuleCreateInfo
231 {
232 	VkStructureType				sType;
233 	const void*					pNext;
234 	VkShaderModuleCreateFlags	flags;
235 	deUintptr					codeSize;
236 	const deUint32*				pCode;
237 };
238 
239 #endif // CTS_USES_VULKANSC
240 
241 typedef void* VkRemoteAddressNV;
242 
243 extern "C"
244 {
245 #include "vkFunctionPointerTypes.inl"
246 }
247 
248 class PlatformInterface
249 {
250 public:
251 #include "vkVirtualPlatformInterface.inl"
252 
253 	virtual	GetInstanceProcAddrFunc	getGetInstanceProcAddr	() const = 0;
254 
255 protected:
PlatformInterface(void)256 									PlatformInterface		(void) {}
257 
258 private:
259 									PlatformInterface		(const PlatformInterface&);
260 	PlatformInterface&				operator=				(const PlatformInterface&);
261 };
262 
263 class InstanceInterface
264 {
265 public:
266 #include "vkVirtualInstanceInterface.inl"
267 
268 protected:
InstanceInterface(void)269 						InstanceInterface	(void) {}
270 
271 private:
272 						InstanceInterface	(const InstanceInterface&);
273 	InstanceInterface&	operator=			(const InstanceInterface&);
274 };
275 
276 class DeviceInterface
277 {
278 public:
279 #include "vkVirtualDeviceInterface.inl"
280 
281 #ifdef CTS_USES_VULKANSC
282 	virtual VkResult	createShaderModule	(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule) const = 0;
283 #endif // CTS_USES_VULKANSC
284 
285 protected:
DeviceInterface(void)286 						DeviceInterface		(void) {}
287 
288 private:
289 						DeviceInterface		(const DeviceInterface&);
290 	DeviceInterface&	operator=			(const DeviceInterface&);
291 };
292 
293 class Error : public tcu::TestError
294 {
295 public:
296 					Error				(VkResult error, const char* message, const char* expr, const char* file, int line);
297 					Error				(VkResult error, const std::string& message);
298 	virtual			~Error				(void) throw();
299 
getError(void) const300 	VkResult		getError			(void) const { return m_error; }
301 
302 private:
303 	const VkResult	m_error;
304 };
305 
306 class NotSupportedError : public tcu::NotSupportedError
307 {
308 public:
309 					NotSupportedError	(VkResult error, const char* message, const char* expr, const char* file, int line);
310 					NotSupportedError	(VkResult error, const std::string& message);
311 	virtual			~NotSupportedError	(void) throw();
312 
getError(void) const313 	VkResult		getError			(void) const { return m_error; }
314 
315 private:
316 	const VkResult	m_error;
317 };
318 
319 class OutOfMemoryError : public tcu::ResourceError
320 {
321 public:
322 					OutOfMemoryError	(VkResult error, const char* message, const char* expr, const char* file, int line);
323 					OutOfMemoryError	(VkResult error, const std::string& message);
324 	virtual			~OutOfMemoryError	(void) throw();
325 
getError(void) const326 	VkResult		getError			(void) const { return m_error; }
327 
328 private:
329 	const VkResult	m_error;
330 };
331 
332 void			checkResult				(VkResult result, const char* message, const char* file, int line);
333 void			checkResultSupported	(VkResult result, const char* message, const char* file, int line);
334 void			checkWsiResult			(VkResult result, const char* message, const char* file, int line);
335 
336 } // vk
337 
338 #endif // _VKDEFS_HPP
339