• 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_DEFINE_HANDLE(NAME, TYPE)					typedef struct NAME##_s* NAME
41 #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(NAME, TYPE)	typedef Handle<TYPE> NAME
42 
43 #define VK_DEFINE_PLATFORM_TYPE(NAME, COMPATIBLE)		\
44 namespace pt {											\
45 struct NAME {											\
46 	COMPATIBLE internal;								\
47 	explicit NAME (COMPATIBLE internal_)				\
48 		: internal(internal_) {}						\
49 };														\
50 } // pt
51 
52 #define VK_MAKE_API_VERSION(VARIANT, MAJOR, MINOR, PATCH)	\
53 												((((deUint32)(VARIANT)) << 29) | (((deUint32)(MAJOR)) << 22) | (((deUint32)(MINOR)) << 12) | ((deUint32)(PATCH)))
54 #define VK_MAKE_VERSION(MAJOR, MINOR, PATCH)	VK_MAKE_API_VERSION(0, MAJOR, MINOR, PATCH)
55 #define VK_BIT(NUM)								(1u<<(deUint32)(NUM))
56 
57 #define VK_API_VERSION_VARIANT(version)			((deUint32)(version) >> 29)
58 #define VK_API_VERSION_MAJOR(version)			(((deUint32)(version) >> 22) & 0x7FU)
59 #define VK_API_VERSION_MINOR(version)			(((deUint32)(version) >> 12) & 0x3FFU)
60 #define VK_API_VERSION_PATCH(version)			((deUint32)(version) & 0xFFFU)
61 
62 #define VK_CHECK(EXPR)							vk::checkResult((EXPR), #EXPR, __FILE__, __LINE__)
63 #define VK_CHECK_MSG(EXPR, MSG)					vk::checkResult((EXPR), MSG, __FILE__, __LINE__)
64 #define VK_CHECK_WSI(EXPR)						vk::checkWsiResult((EXPR), #EXPR, __FILE__, __LINE__)
65 
66 /*--------------------------------------------------------------------*//*!
67  * \brief Vulkan utilities
68  *//*--------------------------------------------------------------------*/
69 namespace vk
70 {
71 
72 typedef deUint64	VkDeviceSize;
73 typedef deUint32	VkSampleMask;
74 typedef deUint32	VkBool32;
75 typedef deUint32	VkFlags;
76 typedef deUint64	VkFlags64;
77 typedef deUint64	VkDeviceAddress;
78 
79 // enum HandleType { HANDLE_TYPE_INSTANCE, ... };
80 #include "vkHandleType.inl"
81 
82 template<HandleType Type>
83 class Handle
84 {
85 public:
Handle(void)86 				Handle		(void) {} // \note Left uninitialized on purpose
Handle(deUint64 internal)87 				Handle		(deUint64 internal) : m_internal(internal) {}
88 
operator =(deUint64 internal)89 	Handle&		operator=	(deUint64 internal)					{ m_internal = internal; return *this;			}
90 
operator ==(const Handle<Type> & other) const91 	bool		operator==	(const Handle<Type>& other) const	{ return this->m_internal == other.m_internal;	}
operator !=(const Handle<Type> & other) const92 	bool		operator!=	(const Handle<Type>& other) const	{ return this->m_internal != other.m_internal;	}
93 
operator !(void) const94 	bool		operator!	(void) const						{ return !m_internal;							}
95 
getInternal(void) const96 	deUint64	getInternal	(void) const						{ return m_internal;							}
97 
98 	enum { HANDLE_TYPE = Type };
99 
100 private:
101 	deUint64	m_internal;
102 };
103 
104 #include "vkBasicTypes.inl"
105 
106 #define VK_CORE_FORMAT_LAST			((vk::VkFormat)(vk::VK_FORMAT_ASTC_12x12_SRGB_BLOCK+1))
107 #define VK_CORE_IMAGE_TILING_LAST	((vk::VkImageTiling)(vk::VK_IMAGE_TILING_LINEAR+1))
108 #define VK_CORE_IMAGE_TYPE_LAST		((vk::VkImageType)(vk::VK_IMAGE_TYPE_3D+1))
109 
110 enum SpirvVersion
111 {
112 	SPIRV_VERSION_1_0	= 0,	//!< SPIR-V 1.0
113 	SPIRV_VERSION_1_1	= 1,	//!< SPIR-V 1.1
114 	SPIRV_VERSION_1_2	= 2,	//!< SPIR-V 1.2
115 	SPIRV_VERSION_1_3	= 3,	//!< SPIR-V 1.3
116 	SPIRV_VERSION_1_4	= 4,	//!< SPIR-V 1.4
117 	SPIRV_VERSION_1_5	= 5,	//!< SPIR-V 1.5
118 
119 	SPIRV_VERSION_LAST
120 };
121 
122 typedef struct
123 {
124 	deUint32	magic;
125 	deUint32	version;
126 	deUint32	generator;
127 	deUint32	bound;
128 } SpirvBinaryHeader;
129 
130 namespace wsi
131 {
132 
133 enum Type
134 {
135 	TYPE_XLIB = 0,
136 	TYPE_XCB,
137 	TYPE_WAYLAND,
138 	TYPE_ANDROID,
139 	TYPE_WIN32,
140 	TYPE_MACOS,
141 	TYPE_HEADLESS,
142 
143 	TYPE_LAST
144 };
145 
146 } // wsi
147 
148 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkVoidFunction)					(void);
149 
150 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkAllocationFunction)				(void*						pUserData,
151 																				 size_t						size,
152 																				 size_t						alignment,
153 																				 VkSystemAllocationScope	allocationScope);
154 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkReallocationFunction)			(void*						pUserData,
155 																				 void*						pOriginal,
156 																				 size_t						size,
157 																				 size_t						alignment,
158 																				 VkSystemAllocationScope	allocationScope);
159 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkFreeFunction)					(void*						pUserData,
160 																				 void*						pMem);
161 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalAllocationNotification)	(void*						pUserData,
162 																				 size_t						size,
163 																				 VkInternalAllocationType	allocationType,
164 																				 VkSystemAllocationScope	allocationScope);
165 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalFreeNotification)		(void*						pUserData,
166 																				 size_t						size,
167 																				 VkInternalAllocationType	allocationType,
168 																				 VkSystemAllocationScope	allocationScope);
169 
170 typedef VKAPI_ATTR VkBool32	(VKAPI_CALL* PFN_vkDebugReportCallbackEXT)			(VkDebugReportFlagsEXT		flags,
171 																				 VkDebugReportObjectTypeEXT	objectType,
172 																				 deUint64					object,
173 																				 size_t						location,
174 																				 deInt32					messageCode,
175 																				 const char*				pLayerPrefix,
176 																				 const char*				pMessage,
177 																				 void*						pUserData);
178 
179 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT)	(VkDebugUtilsMessageSeverityFlagBitsEXT				messageSeverity,
180 																				 VkDebugUtilsMessageTypeFlagsEXT					messageTypes,
181 																				 const struct VkDebugUtilsMessengerCallbackDataEXT*	pCallbackData,
182 																				 void*												pUserData);
183 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkDeviceMemoryReportCallbackEXT)	(const struct VkDeviceMemoryReportCallbackDataEXT*	pCallbackData,
184 																				 void*												pUserData);
185 
186 #include "vkStructTypes.inl"
187 
188 typedef void* VkRemoteAddressNV;
189 
190 extern "C"
191 {
192 #include "vkFunctionPointerTypes.inl"
193 }
194 
195 class PlatformInterface
196 {
197 public:
198 #include "vkVirtualPlatformInterface.inl"
199 
200 	virtual	GetInstanceProcAddrFunc	getGetInstanceProcAddr	() const = 0;
201 
202 protected:
PlatformInterface(void)203 									PlatformInterface		(void) {}
204 
205 private:
206 									PlatformInterface		(const PlatformInterface&);
207 	PlatformInterface&				operator=				(const PlatformInterface&);
208 };
209 
210 class InstanceInterface
211 {
212 public:
213 #include "vkVirtualInstanceInterface.inl"
214 
215 protected:
InstanceInterface(void)216 						InstanceInterface	(void) {}
217 
218 private:
219 						InstanceInterface	(const InstanceInterface&);
220 	InstanceInterface&	operator=			(const InstanceInterface&);
221 };
222 
223 class DeviceInterface
224 {
225 public:
226 #include "vkVirtualDeviceInterface.inl"
227 
228 protected:
DeviceInterface(void)229 						DeviceInterface		(void) {}
230 
231 private:
232 						DeviceInterface		(const DeviceInterface&);
233 	DeviceInterface&	operator=			(const DeviceInterface&);
234 };
235 
236 class Error : public tcu::TestError
237 {
238 public:
239 					Error				(VkResult error, const char* message, const char* expr, const char* file, int line);
240 					Error				(VkResult error, const std::string& message);
241 	virtual			~Error				(void) throw();
242 
getError(void) const243 	VkResult		getError			(void) const { return m_error; }
244 
245 private:
246 	const VkResult	m_error;
247 };
248 
249 class OutOfMemoryError : public tcu::ResourceError
250 {
251 public:
252 					OutOfMemoryError	(VkResult error, const char* message, const char* expr, const char* file, int line);
253 					OutOfMemoryError	(VkResult error, const std::string& message);
254 	virtual			~OutOfMemoryError	(void) throw();
255 
getError(void) const256 	VkResult		getError			(void) const { return m_error; }
257 
258 private:
259 	const VkResult	m_error;
260 };
261 
262 void			checkResult			(VkResult result, const char* message, const char* file, int line);
263 void			checkWsiResult		(VkResult result, const char* message, const char* file, int line);
264 
265 } // vk
266 
267 #endif // _VKDEFS_HPP
268