• 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 
209 #ifdef CTS_USES_VULKANSC
210 struct VkFaultData;
211 typedef VKAPI_ATTR void		(VKAPI_CALL *PFN_vkFaultCallbackFunction)			(VkBool32											incompleteFaultData,
212 																				 deUint32											faultCount,
213 																				 const VkFaultData*									pFaultData);
214 #endif // CTS_USES_VULKANSC
215 
216 #include "vkStructTypes.inl"
217 
218 typedef void* VkRemoteAddressNV;
219 
220 extern "C"
221 {
222 #include "vkFunctionPointerTypes.inl"
223 }
224 
225 class PlatformInterface
226 {
227 public:
228 #include "vkVirtualPlatformInterface.inl"
229 
230 	virtual	GetInstanceProcAddrFunc	getGetInstanceProcAddr	() const = 0;
231 
232 protected:
PlatformInterface(void)233 									PlatformInterface		(void) {}
234 
235 private:
236 									PlatformInterface		(const PlatformInterface&);
237 	PlatformInterface&				operator=				(const PlatformInterface&);
238 };
239 
240 class InstanceInterface
241 {
242 public:
243 #include "vkVirtualInstanceInterface.inl"
244 
245 protected:
InstanceInterface(void)246 						InstanceInterface	(void) {}
247 
248 private:
249 						InstanceInterface	(const InstanceInterface&);
250 	InstanceInterface&	operator=			(const InstanceInterface&);
251 };
252 
253 class DeviceInterface
254 {
255 public:
256 #include "vkVirtualDeviceInterface.inl"
257 
258 #ifdef CTS_USES_VULKANSC
259 	virtual VkResult	createShaderModule	(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule) const = 0;
260 #endif // CTS_USES_VULKANSC
261 
262 protected:
DeviceInterface(void)263 						DeviceInterface		(void) {}
264 
265 private:
266 						DeviceInterface		(const DeviceInterface&);
267 	DeviceInterface&	operator=			(const DeviceInterface&);
268 };
269 
270 class Error : public tcu::TestError
271 {
272 public:
273 					Error				(VkResult error, const char* message, const char* expr, const char* file, int line);
274 					Error				(VkResult error, const std::string& message);
275 	virtual			~Error				(void) throw();
276 
getError(void) const277 	VkResult		getError			(void) const { return m_error; }
278 
279 private:
280 	const VkResult	m_error;
281 };
282 
283 class NotSupportedError : public tcu::NotSupportedError
284 {
285 public:
286 					NotSupportedError	(VkResult error, const char* message, const char* expr, const char* file, int line);
287 					NotSupportedError	(VkResult error, const std::string& message);
288 	virtual			~NotSupportedError	(void) throw();
289 
getError(void) const290 	VkResult		getError			(void) const { return m_error; }
291 
292 private:
293 	const VkResult	m_error;
294 };
295 
296 class OutOfMemoryError : public tcu::ResourceError
297 {
298 public:
299 					OutOfMemoryError	(VkResult error, const char* message, const char* expr, const char* file, int line);
300 					OutOfMemoryError	(VkResult error, const std::string& message);
301 	virtual			~OutOfMemoryError	(void) throw();
302 
getError(void) const303 	VkResult		getError			(void) const { return m_error; }
304 
305 private:
306 	const VkResult	m_error;
307 };
308 
309 void			checkResult				(VkResult result, const char* message, const char* file, int line);
310 void			checkResultSupported	(VkResult result, const char* message, const char* file, int line);
311 void			checkWsiResult			(VkResult result, const char* message, const char* file, int line);
312 
313 } // vk
314 
315 #endif // _VKDEFS_HPP
316