Update Vulkan Headers
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkDefs.hpp
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_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:
86                                 Handle          (void) {} // \note Left uninitialized on purpose
87                                 Handle          (deUint64 internal) : m_internal(internal) {}
88
89         Handle&         operator=       (deUint64 internal)                                     { m_internal = internal; return *this;                  }
90
91         bool            operator==      (const Handle<Type>& other) const       { return this->m_internal == other.m_internal;  }
92         bool            operator!=      (const Handle<Type>& other) const       { return this->m_internal != other.m_internal;  }
93
94         bool            operator!       (void) const                                            { return !m_internal;                                                   }
95
96         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 extern "C"
189 {
190 #include "vkFunctionPointerTypes.inl"
191 }
192
193 class PlatformInterface
194 {
195 public:
196 #include "vkVirtualPlatformInterface.inl"
197
198         virtual GetInstanceProcAddrFunc getGetInstanceProcAddr  () const = 0;
199
200 protected:
201                                                                         PlatformInterface               (void) {}
202
203 private:
204                                                                         PlatformInterface               (const PlatformInterface&);
205         PlatformInterface&                              operator=                               (const PlatformInterface&);
206 };
207
208 class InstanceInterface
209 {
210 public:
211 #include "vkVirtualInstanceInterface.inl"
212
213 protected:
214                                                 InstanceInterface       (void) {}
215
216 private:
217                                                 InstanceInterface       (const InstanceInterface&);
218         InstanceInterface&      operator=                       (const InstanceInterface&);
219 };
220
221 class DeviceInterface
222 {
223 public:
224 #include "vkVirtualDeviceInterface.inl"
225
226 protected:
227                                                 DeviceInterface         (void) {}
228
229 private:
230                                                 DeviceInterface         (const DeviceInterface&);
231         DeviceInterface&        operator=                       (const DeviceInterface&);
232 };
233
234 class Error : public tcu::TestError
235 {
236 public:
237                                         Error                           (VkResult error, const char* message, const char* expr, const char* file, int line);
238                                         Error                           (VkResult error, const std::string& message);
239         virtual                 ~Error                          (void) throw();
240
241         VkResult                getError                        (void) const { return m_error; }
242
243 private:
244         const VkResult  m_error;
245 };
246
247 class OutOfMemoryError : public tcu::ResourceError
248 {
249 public:
250                                         OutOfMemoryError        (VkResult error, const char* message, const char* expr, const char* file, int line);
251                                         OutOfMemoryError        (VkResult error, const std::string& message);
252         virtual                 ~OutOfMemoryError       (void) throw();
253
254         VkResult                getError                        (void) const { return m_error; }
255
256 private:
257         const VkResult  m_error;
258 };
259
260 void                    checkResult                     (VkResult result, const char* message, const char* file, int line);
261 void                    checkWsiResult          (VkResult result, const char* message, const char* file, int line);
262
263 } // vk
264
265 #endif // _VKDEFS_HPP