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) && ((defined(_MSC_VER) && _MSC_VER >= 800) || defined(__MINGW32__) || 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: Handle(void)86 Handle (void) {} // \note Left uninitialized on purpose Handle(deUint64 internal)87 Handle (deUint64 internal) : m_internal(internal) {} 88 operator =(deUint64 internal)89 Handle& operator= (deUint64 internal) { m_internal = internal; return *this; } 90 operator ==(const Handle<Type> & other) const91 bool operator== (const Handle<Type>& other) const { return this->m_internal == other.m_internal; } operator !=(const Handle<Type> & other) const92 bool operator!= (const Handle<Type>& other) const { return this->m_internal != other.m_internal; } 93 operator !(void) const94 bool operator! (void) const { return !m_internal; } 95 getInternal(void) const96 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 TYPE_OHOS, 143 144 TYPE_LAST 145 }; 146 147 } // wsi 148 149 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkVoidFunction) (void); 150 151 typedef VKAPI_ATTR void* (VKAPI_CALL* PFN_vkAllocationFunction) (void* pUserData, 152 size_t size, 153 size_t alignment, 154 VkSystemAllocationScope allocationScope); 155 typedef VKAPI_ATTR void* (VKAPI_CALL* PFN_vkReallocationFunction) (void* pUserData, 156 void* pOriginal, 157 size_t size, 158 size_t alignment, 159 VkSystemAllocationScope allocationScope); 160 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkFreeFunction) (void* pUserData, 161 void* pMem); 162 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkInternalAllocationNotification) (void* pUserData, 163 size_t size, 164 VkInternalAllocationType allocationType, 165 VkSystemAllocationScope allocationScope); 166 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkInternalFreeNotification) (void* pUserData, 167 size_t size, 168 VkInternalAllocationType allocationType, 169 VkSystemAllocationScope allocationScope); 170 171 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL* PFN_vkDebugReportCallbackEXT) (VkDebugReportFlagsEXT flags, 172 VkDebugReportObjectTypeEXT objectType, 173 deUint64 object, 174 size_t location, 175 deInt32 messageCode, 176 const char* pLayerPrefix, 177 const char* pMessage, 178 void* pUserData); 179 180 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT) (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, 181 VkDebugUtilsMessageTypeFlagsEXT messageTypes, 182 const struct VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, 183 void* pUserData); 184 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkDeviceMemoryReportCallbackEXT) (const struct VkDeviceMemoryReportCallbackDataEXT* pCallbackData, 185 void* pUserData); 186 187 #include "vkStructTypes.inl" 188 189 typedef void* VkRemoteAddressNV; 190 191 extern "C" 192 { 193 #include "vkFunctionPointerTypes.inl" 194 } 195 196 class PlatformInterface 197 { 198 public: 199 #include "vkVirtualPlatformInterface.inl" 200 201 virtual GetInstanceProcAddrFunc getGetInstanceProcAddr () const = 0; 202 203 protected: PlatformInterface(void)204 PlatformInterface (void) {} 205 206 private: 207 PlatformInterface (const PlatformInterface&); 208 PlatformInterface& operator= (const PlatformInterface&); 209 }; 210 211 class InstanceInterface 212 { 213 public: 214 #include "vkVirtualInstanceInterface.inl" 215 216 protected: InstanceInterface(void)217 InstanceInterface (void) {} 218 219 private: 220 InstanceInterface (const InstanceInterface&); 221 InstanceInterface& operator= (const InstanceInterface&); 222 }; 223 224 class DeviceInterface 225 { 226 public: 227 #include "vkVirtualDeviceInterface.inl" 228 229 protected: DeviceInterface(void)230 DeviceInterface (void) {} 231 232 private: 233 DeviceInterface (const DeviceInterface&); 234 DeviceInterface& operator= (const DeviceInterface&); 235 }; 236 237 class Error : public tcu::TestError 238 { 239 public: 240 Error (VkResult error, const char* message, const char* expr, const char* file, int line); 241 Error (VkResult error, const std::string& message); 242 virtual ~Error (void) throw(); 243 getError(void) const244 VkResult getError (void) const { return m_error; } 245 246 private: 247 const VkResult m_error; 248 }; 249 250 class OutOfMemoryError : public tcu::ResourceError 251 { 252 public: 253 OutOfMemoryError (VkResult error, const char* message, const char* expr, const char* file, int line); 254 OutOfMemoryError (VkResult error, const std::string& message); 255 virtual ~OutOfMemoryError (void) throw(); 256 getError(void) const257 VkResult getError (void) const { return m_error; } 258 259 private: 260 const VkResult m_error; 261 }; 262 263 void checkResult (VkResult result, const char* message, const char* file, int line); 264 void checkWsiResult (VkResult result, const char* message, const char* file, int line); 265 266 } // vk 267 268 #endif // _VKDEFS_HPP 269