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