• 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 
157 	TYPE_LAST
158 };
159 
160 } // wsi
161 
162 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkVoidFunction)					(void);
163 
164 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkAllocationFunction)				(void*						pUserData,
165 																				 size_t						size,
166 																				 size_t						alignment,
167 																				 VkSystemAllocationScope	allocationScope);
168 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkReallocationFunction)			(void*						pUserData,
169 																				 void*						pOriginal,
170 																				 size_t						size,
171 																				 size_t						alignment,
172 																				 VkSystemAllocationScope	allocationScope);
173 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkFreeFunction)					(void*						pUserData,
174 																				 void*						pMem);
175 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalAllocationNotification)	(void*						pUserData,
176 																				 size_t						size,
177 																				 VkInternalAllocationType	allocationType,
178 																				 VkSystemAllocationScope	allocationScope);
179 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalFreeNotification)		(void*						pUserData,
180 																				 size_t						size,
181 																				 VkInternalAllocationType	allocationType,
182 																				 VkSystemAllocationScope	allocationScope);
183 
184 #ifndef CTS_USES_VULKANSC
185 
186 typedef VKAPI_ATTR VkBool32	(VKAPI_CALL* PFN_vkDebugReportCallbackEXT)			(VkDebugReportFlagsEXT		flags,
187 																				 VkDebugReportObjectTypeEXT	objectType,
188 																				 deUint64					object,
189 																				 size_t						location,
190 																				 deInt32					messageCode,
191 																				 const char*				pLayerPrefix,
192 																				 const char*				pMessage,
193 																				 void*						pUserData);
194 
195 typedef VKAPI_ATTR PFN_vkVoidFunction (VKAPI_CALL* PFN_vkGetInstanceProcAddrLUNARG)	(VkInstance instance, const char pName);
196 
197 #endif // CTS_USES_VULKANSC
198 
199 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT)	(VkDebugUtilsMessageSeverityFlagBitsEXT				messageSeverity,
200 																				 VkDebugUtilsMessageTypeFlagsEXT					messageTypes,
201 																				 const struct VkDebugUtilsMessengerCallbackDataEXT*	pCallbackData,
202 																				 void*												pUserData);
203 
204 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkDeviceMemoryReportCallbackEXT)	(const struct VkDeviceMemoryReportCallbackDataEXT*	pCallbackData,
205 																				 void*												pUserData);
206 
207 #ifdef CTS_USES_VULKANSC
208 struct VkFaultData;
209 typedef VKAPI_ATTR void		(VKAPI_CALL *PFN_vkFaultCallbackFunction)			(VkBool32											incompleteFaultData,
210 																				 deUint32											faultCount,
211 																				 VkFaultData*										pFaultData);
212 #endif // CTS_USES_VULKANSC
213 
214 #include "vkStructTypes.inl"
215 
216 #ifdef CTS_USES_VULKANSC
217 
218 // substitute required enums and structs removed from VulkanSC specification
219 
220 enum VkShaderModuleCreateFlagBits
221 {
222 	VK_SHADER_MODULE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF,
223 };
224 typedef deUint32 VkShaderModuleCreateFlags;
225 
226 #define VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO VkStructureType(16)
227 #define VK_OBJECT_TYPE_SHADER_MODULE VkObjectType(15)
228 
229 struct VkShaderModuleCreateInfo
230 {
231 	VkStructureType				sType;
232 	const void*					pNext;
233 	VkShaderModuleCreateFlags	flags;
234 	deUintptr					codeSize;
235 	const deUint32*				pCode;
236 };
237 
238 #endif // CTS_USES_VULKANSC
239 
240 typedef void* VkRemoteAddressNV;
241 
242 extern "C"
243 {
244 #include "vkFunctionPointerTypes.inl"
245 }
246 
247 class PlatformInterface
248 {
249 public:
250 #include "vkVirtualPlatformInterface.inl"
251 
252 	virtual	GetInstanceProcAddrFunc	getGetInstanceProcAddr	() const = 0;
253 
254 protected:
PlatformInterface(void)255 									PlatformInterface		(void) {}
256 
257 private:
258 									PlatformInterface		(const PlatformInterface&);
259 	PlatformInterface&				operator=				(const PlatformInterface&);
260 };
261 
262 class InstanceInterface
263 {
264 public:
265 #include "vkVirtualInstanceInterface.inl"
266 
267 protected:
InstanceInterface(void)268 						InstanceInterface	(void) {}
269 
270 private:
271 						InstanceInterface	(const InstanceInterface&);
272 	InstanceInterface&	operator=			(const InstanceInterface&);
273 };
274 
275 class DeviceInterface
276 {
277 public:
278 #include "vkVirtualDeviceInterface.inl"
279 
280 #ifdef CTS_USES_VULKANSC
281 	virtual VkResult	createShaderModule	(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule) const = 0;
282 #endif // CTS_USES_VULKANSC
283 
284 protected:
DeviceInterface(void)285 						DeviceInterface		(void) {}
286 
287 private:
288 						DeviceInterface		(const DeviceInterface&);
289 	DeviceInterface&	operator=			(const DeviceInterface&);
290 };
291 
292 class Error : public tcu::TestError
293 {
294 public:
295 					Error				(VkResult error, const char* message, const char* expr, const char* file, int line);
296 					Error				(VkResult error, const std::string& message);
297 	virtual			~Error				(void) throw();
298 
getError(void) const299 	VkResult		getError			(void) const { return m_error; }
300 
301 private:
302 	const VkResult	m_error;
303 };
304 
305 class NotSupportedError : public tcu::NotSupportedError
306 {
307 public:
308 					NotSupportedError	(VkResult error, const char* message, const char* expr, const char* file, int line);
309 					NotSupportedError	(VkResult error, const std::string& message);
310 	virtual			~NotSupportedError	(void) throw();
311 
getError(void) const312 	VkResult		getError			(void) const { return m_error; }
313 
314 private:
315 	const VkResult	m_error;
316 };
317 
318 class OutOfMemoryError : public tcu::ResourceError
319 {
320 public:
321 					OutOfMemoryError	(VkResult error, const char* message, const char* expr, const char* file, int line);
322 					OutOfMemoryError	(VkResult error, const std::string& message);
323 	virtual			~OutOfMemoryError	(void) throw();
324 
getError(void) const325 	VkResult		getError			(void) const { return m_error; }
326 
327 private:
328 	const VkResult	m_error;
329 };
330 
331 void			checkResult				(VkResult result, const char* message, const char* file, int line);
332 void			checkResultSupported	(VkResult result, const char* message, const char* file, int line);
333 void			checkWsiResult			(VkResult result, const char* message, const char* file, int line);
334 
335 } // vk
336 
337 #endif // _VKDEFS_HPP
338