Change unnamed enum VK_ constants to defines and update API
[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_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:
76                                 Handle          (void) {} // \note Left uninitialized on purpose
77                                 Handle          (deUint64 internal) : m_internal(internal) {}
78
79         Handle&         operator=       (deUint64 internal)                                     { m_internal = internal; return *this;                  }
80
81         bool            operator==      (const Handle<Type>& other) const       { return this->m_internal == other.m_internal;  }
82         bool            operator!=      (const Handle<Type>& other) const       { return this->m_internal != other.m_internal;  }
83
84         bool            operator!       (void) const                                            { return !m_internal;                                                   }
85
86         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 namespace wsi
97 {
98
99 enum Type
100 {
101         TYPE_XLIB = 0,
102         TYPE_XCB,
103         TYPE_WAYLAND,
104         TYPE_MIR,
105         TYPE_ANDROID,
106         TYPE_WIN32,
107
108         TYPE_LAST
109 };
110
111 } // wsi
112
113 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkVoidFunction)                                        (void);
114
115 typedef VKAPI_ATTR void*        (VKAPI_CALL* PFN_vkAllocationFunction)                          (void*                                          pUserData,
116                                                                                                                                                                  size_t                                         size,
117                                                                                                                                                                  size_t                                         alignment,
118                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
119 typedef VKAPI_ATTR void*        (VKAPI_CALL* PFN_vkReallocationFunction)                        (void*                                          pUserData,
120                                                                                                                                                                  void*                                          pOriginal,
121                                                                                                                                                                  size_t                                         size,
122                                                                                                                                                                  size_t                                         alignment,
123                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
124 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkFreeFunction)                                        (void*                                          pUserData,
125                                                                                                                                                                  void*                                          pMem);
126 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkInternalAllocationNotification)      (void*                                          pUserData,
127                                                                                                                                                                  size_t                                         size,
128                                                                                                                                                                  VkInternalAllocationType       allocationType,
129                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
130 typedef VKAPI_ATTR void         (VKAPI_CALL* PFN_vkInternalFreeNotification)            (void*                                          pUserData,
131                                                                                                                                                                  size_t                                         size,
132                                                                                                                                                                  VkInternalAllocationType       allocationType,
133                                                                                                                                                                  VkSystemAllocationScope        allocationScope);
134
135 typedef VKAPI_ATTR VkBool32     (VKAPI_CALL* PFN_vkDebugReportCallbackEXT)                      (VkDebugReportFlagsEXT          flags,
136                                                                                                                                                                  VkDebugReportObjectTypeEXT     objectType,
137                                                                                                                                                                  deUint64                                       object,
138                                                                                                                                                                  size_t                                         location,
139                                                                                                                                                                  deInt32                                        messageCode,
140                                                                                                                                                                  const char*                            pLayerPrefix,
141                                                                                                                                                                  const char*                            pMessage,
142                                                                                                                                                                  void*                                          pUserData);
143
144 #include "vkStructTypes.inl"
145
146 extern "C"
147 {
148 #include "vkFunctionPointerTypes.inl"
149 }
150
151 class PlatformInterface
152 {
153 public:
154 #include "vkVirtualPlatformInterface.inl"
155
156 protected:
157                                                 PlatformInterface       (void) {}
158
159 private:
160                                                 PlatformInterface       (const PlatformInterface&);
161         PlatformInterface&      operator=                       (const PlatformInterface&);
162 };
163
164 class InstanceInterface
165 {
166 public:
167 #include "vkVirtualInstanceInterface.inl"
168
169 protected:
170                                                 InstanceInterface       (void) {}
171
172 private:
173                                                 InstanceInterface       (const InstanceInterface&);
174         InstanceInterface&      operator=                       (const InstanceInterface&);
175 };
176
177 class DeviceInterface
178 {
179 public:
180 #include "vkVirtualDeviceInterface.inl"
181
182 protected:
183                                                 DeviceInterface         (void) {}
184
185 private:
186                                                 DeviceInterface         (const DeviceInterface&);
187         DeviceInterface&        operator=                       (const DeviceInterface&);
188 };
189
190 class Error : public tcu::TestError
191 {
192 public:
193                                         Error                           (VkResult error, const char* message, const char* expr, const char* file, int line);
194                                         Error                           (VkResult error, const std::string& message);
195         virtual                 ~Error                          (void) throw();
196
197         VkResult                getError                        (void) const { return m_error; }
198
199 private:
200         const VkResult  m_error;
201 };
202
203 class OutOfMemoryError : public tcu::ResourceError
204 {
205 public:
206                                         OutOfMemoryError        (VkResult error, const char* message, const char* expr, const char* file, int line);
207                                         OutOfMemoryError        (VkResult error, const std::string& message);
208         virtual                 ~OutOfMemoryError       (void) throw();
209
210         VkResult                getError                        (void) const { return m_error; }
211
212 private:
213         const VkResult  m_error;
214 };
215
216 void                    checkResult                     (VkResult result, const char* message, const char* file, int line);
217
218 } // vk
219
220 #endif // _VKDEFS_HPP