Merge changes Iafe8d14c,I4619c2f8,I4e469b93 into nyc-dev
[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  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and/or associated documentation files (the
11  * "Materials"), to deal in the Materials without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Materials, and to
14  * permit persons to whom the Materials are furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice(s) and this permission notice shall be
18  * included in all copies or substantial portions of the Materials.
19  *
20  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27  *
28  *//*!
29  * \file
30  * \brief Vulkan utilites.
31  *//*--------------------------------------------------------------------*/
32
33 #include "tcuDefs.hpp"
34
35 #if (DE_OS == DE_OS_ANDROID) && defined(__ARM_ARCH_7A__)
36 #       define VKAPI_ATTR __attribute__((pcs("aapcs-vfp")))
37 #else
38 #       define VKAPI_ATTR
39 #endif
40
41 #if (DE_OS == DE_OS_WIN32) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
42 #       define VKAPI_CALL __stdcall
43 #else
44 #       define VKAPI_CALL
45 #endif
46
47 #define VK_DEFINE_HANDLE(NAME, TYPE)                                    typedef struct NAME##_s* NAME
48 #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(NAME, TYPE)   typedef Handle<TYPE> NAME
49
50 #define VK_DEFINE_PLATFORM_TYPE(NAME, COMPATIBLE)               \
51 namespace pt {                                                                                  \
52 struct NAME {                                                                                   \
53         COMPATIBLE internal;                                                            \
54         explicit NAME (COMPATIBLE internal_)                            \
55                 : internal(internal_) {}                                                \
56 };                                                                                                              \
57 } // pt
58
59 #define VK_MAKE_VERSION(MAJOR, MINOR, PATCH)    ((MAJOR << 22) | (MINOR << 12) | PATCH)
60 #define VK_BIT(NUM)                                                             (1<<NUM)
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
65 /*--------------------------------------------------------------------*//*!
66  * \brief Vulkan utilities
67  *//*--------------------------------------------------------------------*/
68 namespace vk
69 {
70
71 typedef deUint64        VkDeviceSize;
72 typedef deUint32        VkSampleMask;
73 typedef deUint32        VkBool32;
74 typedef deUint32        VkFlags;
75
76 // enum HandleType { HANDLE_TYPE_INSTANCE, ... };
77 #include "vkHandleType.inl"
78
79 template<HandleType Type>
80 class Handle
81 {
82 public:
83                                 Handle          (void) {} // \note Left uninitialized on purpose
84                                 Handle          (deUint64 internal) : m_internal(internal) {}
85
86         Handle&         operator=       (deUint64 internal)                                     { m_internal = internal; return *this;                  }
87
88         bool            operator==      (const Handle<Type>& other) const       { return this->m_internal == other.m_internal;  }
89         bool            operator!=      (const Handle<Type>& other) const       { return this->m_internal != other.m_internal;  }
90
91         bool            operator!       (void) const                                            { return !m_internal;                                                   }
92
93         deUint64        getInternal     (void) const                                            { return m_internal;                                                    }
94
95         enum { HANDLE_TYPE = Type };
96
97 private:
98         deUint64        m_internal;
99 };
100
101 #include "vkBasicTypes.inl"
102
103 enum { VK_QUEUE_FAMILY_IGNORED          = 0xffffffff    };
104 enum { VK_NO_ATTACHMENT                         = 0xffffffff    };
105
106 enum
107 {
108         VK_FALSE                = 0,
109         VK_TRUE                 = 1,
110         VK_WHOLE_SIZE   = (~0ULL),
111 };
112
113 namespace wsi
114 {
115
116 enum Type
117 {
118         TYPE_XLIB = 0,
119         TYPE_XCB,
120         TYPE_WAYLAND,
121         TYPE_MIR,
122         TYPE_ANDROID,
123         TYPE_WIN32,
124
125         TYPE_LAST
126 };
127
128 } // wsi
129
130 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkVoidFunction)                                        (void);
131
132 typedef VKAPI_ATTR void*        (VKAPI_CALL* PFN_vkAllocationFunction)                          (void*                                          pUserData,
133                                                                                                                                                                  size_t                                         size,
134                                                                                                                                                                  size_t                                         alignment,
135                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
136 typedef VKAPI_ATTR void*        (VKAPI_CALL* PFN_vkReallocationFunction)                        (void*                                          pUserData,
137                                                                                                                                                                  void*                                          pOriginal,
138                                                                                                                                                                  size_t                                         size,
139                                                                                                                                                                  size_t                                         alignment,
140                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
141 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkFreeFunction)                                        (void*                                          pUserData,
142                                                                                                                                                                  void*                                          pMem);
143 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkInternalAllocationNotification)      (void*                                          pUserData,
144                                                                                                                                                                  size_t                                         size,
145                                                                                                                                                                  VkInternalAllocationType       allocationType,
146                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
147 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkInternalFreeNotification)            (void*                                          pUserData,
148                                                                                                                                                                  size_t                                         size,
149                                                                                                                                                                  VkInternalAllocationType       allocationType,
150                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
151
152 typedef VKAPI_ATTR VkBool32     (VKAPI_CALL* PFN_vkDebugReportCallbackEXT)                      (VkDebugReportFlagsEXT          flags,
153                                                                                                                                                                  VkDebugReportObjectTypeEXT     objectType,
154                                                                                                                                                                  deUint64                                       object,
155                                                                                                                                                                  size_t                                         location,
156                                                                                                                                                                  deInt32                                        messageCode,
157                                                                                                                                                                  const char*                            pLayerPrefix,
158                                                                                                                                                                  const char*                            pMessage,
159                                                                                                                                                                  void*                                          pUserData);
160
161 #include "vkStructTypes.inl"
162
163 extern "C"
164 {
165 #include "vkFunctionPointerTypes.inl"
166 }
167
168 class PlatformInterface
169 {
170 public:
171 #include "vkVirtualPlatformInterface.inl"
172
173 protected:
174                                                 PlatformInterface       (void) {}
175
176 private:
177                                                 PlatformInterface       (const PlatformInterface&);
178         PlatformInterface&      operator=                       (const PlatformInterface&);
179 };
180
181 class InstanceInterface
182 {
183 public:
184 #include "vkVirtualInstanceInterface.inl"
185
186 protected:
187                                                 InstanceInterface       (void) {}
188
189 private:
190                                                 InstanceInterface       (const InstanceInterface&);
191         InstanceInterface&      operator=                       (const InstanceInterface&);
192 };
193
194 class DeviceInterface
195 {
196 public:
197 #include "vkVirtualDeviceInterface.inl"
198
199 protected:
200                                                 DeviceInterface         (void) {}
201
202 private:
203                                                 DeviceInterface         (const DeviceInterface&);
204         DeviceInterface&        operator=                       (const DeviceInterface&);
205 };
206
207 class Error : public tcu::TestError
208 {
209 public:
210                                         Error                           (VkResult error, const char* message, const char* expr, const char* file, int line);
211                                         Error                           (VkResult error, const std::string& message);
212         virtual                 ~Error                          (void) throw();
213
214         VkResult                getError                        (void) const { return m_error; }
215
216 private:
217         const VkResult  m_error;
218 };
219
220 class OutOfMemoryError : public tcu::ResourceError
221 {
222 public:
223                                         OutOfMemoryError        (VkResult error, const char* message, const char* expr, const char* file, int line);
224                                         OutOfMemoryError        (VkResult error, const std::string& message);
225         virtual                 ~OutOfMemoryError       (void) throw();
226
227         VkResult                getError                        (void) const { return m_error; }
228
229 private:
230         const VkResult  m_error;
231 };
232
233 void                    checkResult                     (VkResult result, const char* message, const char* file, int line);
234
235 } // vk
236
237 #endif // _VKDEFS_HPP