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_VERSION(MAJOR, MINOR, PATCH) (((deUint32)(MAJOR) << 22u) | ((deUint32)(MINOR) << 12u) | (deUint32)(PATCH)) 53 #define VK_BIT(NUM) (1u<<(deUint32)(NUM)) 54 55 #define VK_VERSION_MAJOR(version) ((deUint32)(version) >> 22) 56 #define VK_VERSION_MINOR(version) (((deUint32)(version) >> 12) & 0x3ff) 57 #define VK_VERSION_PATCH(version) ((deUint32)(version) & 0xfff) 58 59 #define VK_CHECK(EXPR) vk::checkResult((EXPR), #EXPR, __FILE__, __LINE__) 60 #define VK_CHECK_MSG(EXPR, MSG) vk::checkResult((EXPR), MSG, __FILE__, __LINE__) 61 #define VK_CHECK_WSI(EXPR) vk::checkWsiResult((EXPR), #EXPR, __FILE__, __LINE__) 62 63 /*--------------------------------------------------------------------*//*! 64 * \brief Vulkan utilities 65 *//*--------------------------------------------------------------------*/ 66 namespace vk 67 { 68 69 typedef deUint64 VkDeviceSize; 70 typedef deUint32 VkSampleMask; 71 typedef deUint32 VkBool32; 72 typedef deUint32 VkFlags; 73 typedef deUint64 VkDeviceAddress; 74 75 // enum HandleType { HANDLE_TYPE_INSTANCE, ... }; 76 #include "vkHandleType.inl" 77 78 template<HandleType Type> 79 class Handle 80 { 81 public: Handle(void)82 Handle (void) {} // \note Left uninitialized on purpose Handle(deUint64 internal)83 Handle (deUint64 internal) : m_internal(internal) {} 84 operator =(deUint64 internal)85 Handle& operator= (deUint64 internal) { m_internal = internal; return *this; } 86 operator ==(const Handle<Type> & other) const87 bool operator== (const Handle<Type>& other) const { return this->m_internal == other.m_internal; } operator !=(const Handle<Type> & other) const88 bool operator!= (const Handle<Type>& other) const { return this->m_internal != other.m_internal; } 89 operator !(void) const90 bool operator! (void) const { return !m_internal; } 91 getInternal(void) const92 deUint64 getInternal (void) const { return m_internal; } 93 94 enum { HANDLE_TYPE = Type }; 95 96 private: 97 deUint64 m_internal; 98 }; 99 100 #include "vkBasicTypes.inl" 101 102 #define VK_CORE_FORMAT_LAST ((vk::VkFormat)(vk::VK_FORMAT_ASTC_12x12_SRGB_BLOCK+1)) 103 104 enum SpirvVersion 105 { 106 SPIRV_VERSION_1_0 = 0, //!< SPIR-V 1.0 107 SPIRV_VERSION_1_1 = 1, //!< SPIR-V 1.1 108 SPIRV_VERSION_1_2 = 2, //!< SPIR-V 1.2 109 SPIRV_VERSION_1_3 = 3, //!< SPIR-V 1.3 110 SPIRV_VERSION_1_4 = 4, //!< SPIR-V 1.4 111 SPIRV_VERSION_1_5 = 5, //!< SPIR-V 1.5 112 113 SPIRV_VERSION_LAST 114 }; 115 116 typedef struct 117 { 118 deUint32 magic; 119 deUint32 version; 120 deUint32 generator; 121 deUint32 bound; 122 } SpirvBinaryHeader; 123 124 namespace wsi 125 { 126 127 enum Type 128 { 129 TYPE_XLIB = 0, 130 TYPE_XCB, 131 TYPE_WAYLAND, 132 TYPE_ANDROID, 133 TYPE_WIN32, 134 TYPE_MACOS, 135 136 TYPE_LAST 137 }; 138 139 } // wsi 140 141 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkVoidFunction) (void); 142 143 typedef VKAPI_ATTR void* (VKAPI_CALL* PFN_vkAllocationFunction) (void* pUserData, 144 size_t size, 145 size_t alignment, 146 VkSystemAllocationScope allocationScope); 147 typedef VKAPI_ATTR void* (VKAPI_CALL* PFN_vkReallocationFunction) (void* pUserData, 148 void* pOriginal, 149 size_t size, 150 size_t alignment, 151 VkSystemAllocationScope allocationScope); 152 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkFreeFunction) (void* pUserData, 153 void* pMem); 154 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkInternalAllocationNotification) (void* pUserData, 155 size_t size, 156 VkInternalAllocationType allocationType, 157 VkSystemAllocationScope allocationScope); 158 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkInternalFreeNotification) (void* pUserData, 159 size_t size, 160 VkInternalAllocationType allocationType, 161 VkSystemAllocationScope allocationScope); 162 163 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL* PFN_vkDebugReportCallbackEXT) (VkDebugReportFlagsEXT flags, 164 VkDebugReportObjectTypeEXT objectType, 165 deUint64 object, 166 size_t location, 167 deInt32 messageCode, 168 const char* pLayerPrefix, 169 const char* pMessage, 170 void* pUserData); 171 172 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT) (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, 173 VkDebugUtilsMessageTypeFlagsEXT messageTypes, 174 const struct VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, 175 void* pUserData); 176 177 #include "vkStructTypes.inl" 178 179 extern "C" 180 { 181 #include "vkFunctionPointerTypes.inl" 182 } 183 184 class PlatformInterface 185 { 186 public: 187 #include "vkVirtualPlatformInterface.inl" 188 189 virtual GetInstanceProcAddrFunc getGetInstanceProcAddr () const = 0; 190 191 protected: PlatformInterface(void)192 PlatformInterface (void) {} 193 194 private: 195 PlatformInterface (const PlatformInterface&); 196 PlatformInterface& operator= (const PlatformInterface&); 197 }; 198 199 class InstanceInterface 200 { 201 public: 202 #include "vkVirtualInstanceInterface.inl" 203 204 protected: InstanceInterface(void)205 InstanceInterface (void) {} 206 207 private: 208 InstanceInterface (const InstanceInterface&); 209 InstanceInterface& operator= (const InstanceInterface&); 210 }; 211 212 class DeviceInterface 213 { 214 public: 215 #include "vkVirtualDeviceInterface.inl" 216 217 protected: DeviceInterface(void)218 DeviceInterface (void) {} 219 220 private: 221 DeviceInterface (const DeviceInterface&); 222 DeviceInterface& operator= (const DeviceInterface&); 223 }; 224 225 class Error : public tcu::TestError 226 { 227 public: 228 Error (VkResult error, const char* message, const char* expr, const char* file, int line); 229 Error (VkResult error, const std::string& message); 230 virtual ~Error (void) throw(); 231 getError(void) const232 VkResult getError (void) const { return m_error; } 233 234 private: 235 const VkResult m_error; 236 }; 237 238 class OutOfMemoryError : public tcu::ResourceError 239 { 240 public: 241 OutOfMemoryError (VkResult error, const char* message, const char* expr, const char* file, int line); 242 OutOfMemoryError (VkResult error, const std::string& message); 243 virtual ~OutOfMemoryError (void) throw(); 244 getError(void) const245 VkResult getError (void) const { return m_error; } 246 247 private: 248 const VkResult m_error; 249 }; 250 251 void checkResult (VkResult result, const char* message, const char* file, int line); 252 void checkWsiResult (VkResult result, const char* message, const char* file, int line); 253 254 } // vk 255 256 #endif // _VKDEFS_HPP 257