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) && \
35 ((defined(_MSC_VER) && _MSC_VER >= 800) || defined(__MINGW32__) || defined(_STDCALL_SUPPORTED))
36 #define VKAPI_CALL __stdcall
37 #else
38 #define VKAPI_CALL
39 #endif
40
41 #define VK_NULL_HANDLE DE_NULL
42 #define VK_DEFINE_HANDLE(NAME, TYPE) typedef struct NAME##_s *NAME
43 #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(NAME, TYPE) typedef Handle<TYPE> NAME
44
45 #define VK_DEFINE_PLATFORM_TYPE(NAME, COMPATIBLE) \
46 namespace pt \
47 { \
48 struct NAME \
49 { \
50 COMPATIBLE internal; \
51 explicit NAME(COMPATIBLE internal_) : internal(internal_) \
52 { \
53 } \
54 }; \
55 } // pt
56
57 #define VK_MAKE_API_VERSION(VARIANT, MAJOR, MINOR, PATCH) \
58 ((((uint32_t)(VARIANT)) << 29) | (((uint32_t)(MAJOR)) << 22) | (((uint32_t)(MINOR)) << 12) | ((uint32_t)(PATCH)))
59 #define VKSC_API_VARIANT 1
60 #define VK_MAKE_VERSION(MAJOR, MINOR, PATCH) VK_MAKE_API_VERSION(0, MAJOR, MINOR, PATCH)
61 #define VK_BIT(NUM) (1u << (uint32_t)(NUM))
62
63 #define VK_API_VERSION_VARIANT(version) ((uint32_t)(version) >> 29)
64 #define VK_API_VERSION_MAJOR(version) (((uint32_t)(version) >> 22) & 0x7FU)
65 #define VK_API_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3FFU)
66 #define VK_API_VERSION_PATCH(version) ((uint32_t)(version)&0xFFFU)
67
68 #define VK_CHECK(EXPR) vk::checkResult((EXPR), #EXPR, __FILE__, __LINE__)
69 #define VK_CHECK_SUPPORTED(EXPR) vk::checkResultSupported((EXPR), #EXPR, __FILE__, __LINE__)
70 #define VK_CHECK_MSG(EXPR, MSG) vk::checkResult((EXPR), MSG, __FILE__, __LINE__)
71 #define VK_CHECK_WSI(EXPR) vk::checkWsiResult((EXPR), #EXPR, __FILE__, __LINE__)
72
73 #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \
74 ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch)))
75
76 /*--------------------------------------------------------------------*//*!
77 * \brief Vulkan utilities
78 *//*--------------------------------------------------------------------*/
79 namespace vk
80 {
81
82 typedef uint64_t VkDeviceSize;
83 typedef uint32_t VkSampleMask;
84 typedef uint32_t VkBool32;
85 typedef uint32_t VkFlags;
86 typedef uint64_t VkFlags64;
87 typedef uint64_t VkDeviceAddress;
88
89 // enum HandleType { HANDLE_TYPE_INSTANCE, ... };
90 #include "vkHandleType.inl"
91
92 template <HandleType Type>
93 class Handle
94 {
95 public:
Handle(void)96 Handle(void)
97 {
98 } // \note Left uninitialized on purpose
Handle(uint64_t internal)99 Handle(uint64_t internal) : m_internal(internal)
100 {
101 }
102
operator =(uint64_t internal)103 Handle &operator=(uint64_t internal)
104 {
105 m_internal = internal;
106 return *this;
107 }
108
operator ==(const Handle<Type> & other) const109 bool operator==(const Handle<Type> &other) const
110 {
111 return this->m_internal == other.m_internal;
112 }
operator !=(const Handle<Type> & other) const113 bool operator!=(const Handle<Type> &other) const
114 {
115 return this->m_internal != other.m_internal;
116 }
117
operator !(void) const118 bool operator!(void) const
119 {
120 return !m_internal;
121 }
122
getInternal(void) const123 uint64_t getInternal(void) const
124 {
125 return m_internal;
126 }
127
128 enum
129 {
130 HANDLE_TYPE = Type
131 };
132
133 private:
134 uint64_t m_internal;
135 };
136
137 template <HandleType Type>
operator <(const Handle<Type> & lhs,const Handle<Type> & rhs)138 bool operator<(const Handle<Type> &lhs, const Handle<Type> &rhs)
139 {
140 return lhs.getInternal() < rhs.getInternal();
141 }
142
143 #include "vkBasicTypes.inl"
144
145 #define VK_CORE_FORMAT_LAST ((vk::VkFormat)(vk::VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1))
146 #define VK_CORE_IMAGE_TILING_LAST ((vk::VkImageTiling)(vk::VK_IMAGE_TILING_LINEAR + 1))
147 #define VK_CORE_IMAGE_TYPE_LAST ((vk::VkImageType)(vk::VK_IMAGE_TYPE_3D + 1))
148
149 enum SpirvVersion
150 {
151 SPIRV_VERSION_1_0 = 0, //!< SPIR-V 1.0
152 SPIRV_VERSION_1_1 = 1, //!< SPIR-V 1.1
153 SPIRV_VERSION_1_2 = 2, //!< SPIR-V 1.2
154 SPIRV_VERSION_1_3 = 3, //!< SPIR-V 1.3
155 SPIRV_VERSION_1_4 = 4, //!< SPIR-V 1.4
156 SPIRV_VERSION_1_5 = 5, //!< SPIR-V 1.5
157 SPIRV_VERSION_1_6 = 6, //!< SPIR-V 1.6
158
159 SPIRV_VERSION_LAST
160 };
161
162 typedef struct
163 {
164 uint32_t magic;
165 uint32_t version;
166 uint32_t generator;
167 uint32_t bound;
168 } SpirvBinaryHeader;
169
170 namespace wsi
171 {
172
173 enum Type
174 {
175 TYPE_XLIB = 0,
176 TYPE_XCB,
177 TYPE_WAYLAND,
178 TYPE_ANDROID,
179 TYPE_WIN32,
180 TYPE_MACOS,
181 TYPE_HEADLESS,
182 TYPE_DIRECT_DRM,
183
184 TYPE_LAST
185 };
186
187 } // namespace wsi
188
189 typedef VKAPI_ATTR void(VKAPI_CALL *PFN_vkVoidFunction)(void);
190
191 typedef VKAPI_ATTR void *(VKAPI_CALL *PFN_vkAllocationFunction)(void *pUserData, size_t size, size_t alignment,
192 VkSystemAllocationScope allocationScope);
193 typedef VKAPI_ATTR void *(VKAPI_CALL *PFN_vkReallocationFunction)(void *pUserData, void *pOriginal, size_t size,
194 size_t alignment,
195 VkSystemAllocationScope allocationScope);
196 typedef VKAPI_ATTR void(VKAPI_CALL *PFN_vkFreeFunction)(void *pUserData, void *pMem);
197 typedef VKAPI_ATTR void(VKAPI_CALL *PFN_vkInternalAllocationNotification)(void *pUserData, size_t size,
198 VkInternalAllocationType allocationType,
199 VkSystemAllocationScope allocationScope);
200 typedef VKAPI_ATTR void(VKAPI_CALL *PFN_vkInternalFreeNotification)(void *pUserData, size_t size,
201 VkInternalAllocationType allocationType,
202 VkSystemAllocationScope allocationScope);
203
204 #ifndef CTS_USES_VULKANSC
205
206 typedef VKAPI_ATTR VkBool32(VKAPI_CALL *PFN_vkDebugReportCallbackEXT)(VkDebugReportFlagsEXT flags,
207 VkDebugReportObjectTypeEXT objectType,
208 uint64_t object, size_t location,
209 int32_t messageCode, const char *pLayerPrefix,
210 const char *pMessage, void *pUserData);
211
212 typedef VKAPI_ATTR PFN_vkVoidFunction(VKAPI_CALL *PFN_vkGetInstanceProcAddrLUNARG)(VkInstance instance,
213 const char pName);
214
215 #endif // CTS_USES_VULKANSC
216
217 typedef VKAPI_ATTR VkBool32(VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT)(
218 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
219 const struct VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData);
220
221 typedef VKAPI_ATTR void(VKAPI_CALL *PFN_vkDeviceMemoryReportCallbackEXT)(
222 const struct VkDeviceMemoryReportCallbackDataEXT *pCallbackData, void *pUserData);
223
224 #ifdef CTS_USES_VULKANSC
225 struct VkFaultData;
226 typedef VKAPI_ATTR void(VKAPI_CALL *PFN_vkFaultCallbackFunction)(VkBool32 incompleteFaultData, uint32_t faultCount,
227 const VkFaultData *pFaultData);
228 #endif // CTS_USES_VULKANSC
229
230 #include "vkStructTypes.inl"
231
232 typedef void *VkRemoteAddressNV;
233
234 extern "C"
235 {
236 #include "vkFunctionPointerTypes.inl"
237 }
238
239 class PlatformInterface
240 {
241 public:
242 #include "vkVirtualPlatformInterface.inl"
243
244 virtual GetInstanceProcAddrFunc getGetInstanceProcAddr() const = 0;
245
246 protected:
PlatformInterface(void)247 PlatformInterface(void)
248 {
249 }
250
251 private:
252 PlatformInterface(const PlatformInterface &);
253 PlatformInterface &operator=(const PlatformInterface &);
254 };
255
256 class InstanceInterface
257 {
258 public:
259 #include "vkVirtualInstanceInterface.inl"
260
261 protected:
InstanceInterface(void)262 InstanceInterface(void)
263 {
264 }
265
266 private:
267 InstanceInterface(const InstanceInterface &);
268 InstanceInterface &operator=(const InstanceInterface &);
269 };
270
271 class DeviceInterface
272 {
273 public:
274 #include "vkVirtualDeviceInterface.inl"
275
276 #ifdef CTS_USES_VULKANSC
277 virtual VkResult createShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
278 const VkAllocationCallbacks *pAllocator,
279 VkShaderModule *pShaderModule) const = 0;
280 #endif // CTS_USES_VULKANSC
281
282 protected:
DeviceInterface(void)283 DeviceInterface(void)
284 {
285 }
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, qpTestResult result);
296 Error(VkResult error, const char *message, const char *expr, const char *file, int line);
297 Error(VkResult error, const std::string &message);
298 virtual ~Error(void) throw();
299
getError(void) const300 VkResult getError(void) const
301 {
302 return m_error;
303 }
304
305 private:
306 const VkResult m_error;
307 };
308
309 class NotSupportedError : public tcu::NotSupportedError
310 {
311 public:
312 NotSupportedError(VkResult error, const char *message, const char *expr, const char *file, int line);
313 NotSupportedError(VkResult error, const std::string &message);
314 virtual ~NotSupportedError(void) throw();
315
getError(void) const316 VkResult getError(void) const
317 {
318 return m_error;
319 }
320
321 private:
322 const VkResult m_error;
323 };
324
325 class OutOfMemoryError : public tcu::ResourceError
326 {
327 public:
328 OutOfMemoryError(VkResult error, const char *message, const char *expr, const char *file, int line);
329 OutOfMemoryError(VkResult error, const std::string &message);
330 virtual ~OutOfMemoryError(void) throw();
331
getError(void) const332 VkResult getError(void) const
333 {
334 return m_error;
335 }
336
337 private:
338 const VkResult m_error;
339 };
340
341 void checkResult(VkResult result, const char *message, const char *file, int line);
342 void checkResultSupported(VkResult result, const char *message, const char *file, int line);
343 void checkWsiResult(VkResult result, const char *message, const char *file, int line);
344
345 } // namespace vk
346
347 #endif // _VKDEFS_HPP
348