• 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) && ((_MSC_VER >= 800) || 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_VERSION(MAJOR, MINOR, PATCH)	(((deUint32)(MAJOR) << 22u) | ((deUint32)(MINOR) << 12u) | (deUint32)(PATCH))
53 #define VK_BIT(NUM)								(1u<<(deUint32)(NUM))
54 
55 #define VK_VERSION_MAJOR(version)				((deUint32)(version) >> 22)
56 #define VK_VERSION_MINOR(version)				(((deUint32)(version) >> 12) & 0x3ff)
57 #define VK_VERSION_PATCH(version)				((deUint32)(version) & 0xfff)
58 
59 #define VK_CHECK(EXPR)							vk::checkResult((EXPR), #EXPR, __FILE__, __LINE__)
60 #define VK_CHECK_MSG(EXPR, MSG)					vk::checkResult((EXPR), MSG, __FILE__, __LINE__)
61 #define VK_CHECK_WSI(EXPR)						vk::checkWsiResult((EXPR), #EXPR, __FILE__, __LINE__)
62 
63 /*--------------------------------------------------------------------*//*!
64  * \brief Vulkan utilities
65  *//*--------------------------------------------------------------------*/
66 namespace vk
67 {
68 
69 typedef deUint64	VkDeviceSize;
70 typedef deUint32	VkSampleMask;
71 typedef deUint32	VkBool32;
72 typedef deUint32	VkFlags;
73 
74 // enum HandleType { HANDLE_TYPE_INSTANCE, ... };
75 #include "vkHandleType.inl"
76 
77 template<HandleType Type>
78 class Handle
79 {
80 public:
Handle(void)81 				Handle		(void) {} // \note Left uninitialized on purpose
Handle(deUint64 internal)82 				Handle		(deUint64 internal) : m_internal(internal) {}
83 
operator =(deUint64 internal)84 	Handle&		operator=	(deUint64 internal)					{ m_internal = internal; return *this;			}
85 
operator ==(const Handle<Type> & other) const86 	bool		operator==	(const Handle<Type>& other) const	{ return this->m_internal == other.m_internal;	}
operator !=(const Handle<Type> & other) const87 	bool		operator!=	(const Handle<Type>& other) const	{ return this->m_internal != other.m_internal;	}
88 
operator !(void) const89 	bool		operator!	(void) const						{ return !m_internal;							}
90 
getInternal(void) const91 	deUint64	getInternal	(void) const						{ return m_internal;							}
92 
93 	enum { HANDLE_TYPE = Type };
94 
95 private:
96 	deUint64	m_internal;
97 };
98 
99 #include "vkBasicTypes.inl"
100 
101 #define VK_CORE_FORMAT_LAST		((vk::VkFormat)(vk::VK_FORMAT_ASTC_12x12_SRGB_BLOCK+1))
102 
103 enum SpirvVersion
104 {
105 	SPIRV_VERSION_1_0	= 0,	//!< SPIR-V 1.0
106 	SPIRV_VERSION_1_1	= 1,	//!< SPIR-V 1.1
107 	SPIRV_VERSION_1_2	= 2,	//!< SPIR-V 1.2
108 	SPIRV_VERSION_1_3	= 3,	//!< SPIR-V 1.3
109 
110 	SPIRV_VERSION_LAST
111 };
112 
113 typedef struct
114 {
115 	deUint32	magic;
116 	deUint32	version;
117 	deUint32	generator;
118 	deUint32	bound;
119 } SpirvBinaryHeader;
120 
121 namespace wsi
122 {
123 
124 enum Type
125 {
126 	TYPE_XLIB = 0,
127 	TYPE_XCB,
128 	TYPE_WAYLAND,
129 	TYPE_MIR,
130 	TYPE_ANDROID,
131 	TYPE_WIN32,
132 	TYPE_MACOS,
133 
134 	TYPE_LAST
135 };
136 
137 } // wsi
138 
139 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkVoidFunction)					(void);
140 
141 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkAllocationFunction)				(void*						pUserData,
142 																				 size_t						size,
143 																				 size_t						alignment,
144 																				 VkSystemAllocationScope	allocationScope);
145 typedef VKAPI_ATTR void*	(VKAPI_CALL* PFN_vkReallocationFunction)			(void*						pUserData,
146 																				 void*						pOriginal,
147 																				 size_t						size,
148 																				 size_t						alignment,
149 																				 VkSystemAllocationScope	allocationScope);
150 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkFreeFunction)					(void*						pUserData,
151 																				 void*						pMem);
152 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalAllocationNotification)	(void*						pUserData,
153 																				 size_t						size,
154 																				 VkInternalAllocationType	allocationType,
155 																				 VkSystemAllocationScope	allocationScope);
156 typedef VKAPI_ATTR void		(VKAPI_CALL* PFN_vkInternalFreeNotification)		(void*						pUserData,
157 																				 size_t						size,
158 																				 VkInternalAllocationType	allocationType,
159 																				 VkSystemAllocationScope	allocationScope);
160 
161 typedef VKAPI_ATTR VkBool32	(VKAPI_CALL* PFN_vkDebugReportCallbackEXT)			(VkDebugReportFlagsEXT		flags,
162 																				 VkDebugReportObjectTypeEXT	objectType,
163 																				 deUint64					object,
164 																				 size_t						location,
165 																				 deInt32					messageCode,
166 																				 const char*				pLayerPrefix,
167 																				 const char*				pMessage,
168 																				 void*						pUserData);
169 
170 #include "vkStructTypes.inl"
171 
172 extern "C"
173 {
174 #include "vkFunctionPointerTypes.inl"
175 }
176 
177 class PlatformInterface
178 {
179 public:
180 #include "vkVirtualPlatformInterface.inl"
181 
182 protected:
PlatformInterface(void)183 						PlatformInterface	(void) {}
184 
185 private:
186 						PlatformInterface	(const PlatformInterface&);
187 	PlatformInterface&	operator=			(const PlatformInterface&);
188 };
189 
190 class InstanceInterface
191 {
192 public:
193 #include "vkVirtualInstanceInterface.inl"
194 
195 protected:
InstanceInterface(void)196 						InstanceInterface	(void) {}
197 
198 private:
199 						InstanceInterface	(const InstanceInterface&);
200 	InstanceInterface&	operator=			(const InstanceInterface&);
201 };
202 
203 class DeviceInterface
204 {
205 public:
206 #include "vkVirtualDeviceInterface.inl"
207 
208 protected:
DeviceInterface(void)209 						DeviceInterface		(void) {}
210 
211 private:
212 						DeviceInterface		(const DeviceInterface&);
213 	DeviceInterface&	operator=			(const DeviceInterface&);
214 };
215 
216 class Error : public tcu::TestError
217 {
218 public:
219 					Error				(VkResult error, const char* message, const char* expr, const char* file, int line);
220 					Error				(VkResult error, const std::string& message);
221 	virtual			~Error				(void) throw();
222 
getError(void) const223 	VkResult		getError			(void) const { return m_error; }
224 
225 private:
226 	const VkResult	m_error;
227 };
228 
229 class OutOfMemoryError : public tcu::ResourceError
230 {
231 public:
232 					OutOfMemoryError	(VkResult error, const char* message, const char* expr, const char* file, int line);
233 					OutOfMemoryError	(VkResult error, const std::string& message);
234 	virtual			~OutOfMemoryError	(void) throw();
235 
getError(void) const236 	VkResult		getError			(void) const { return m_error; }
237 
238 private:
239 	const VkResult	m_error;
240 };
241 
242 void			checkResult			(VkResult result, const char* message, const char* file, int line);
243 void			checkWsiResult		(VkResult result, const char* message, const char* file, int line);
244 
245 } // vk
246 
247 #endif // _VKDEFS_HPP
248