3 /*-------------------------------------------------------------------------
7 * Copyright (c) 2015 Google Inc.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Vulkan utilites.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
28 #if (DE_OS == DE_OS_ANDROID) && defined(__ARM_ARCH) && defined(__ARM_32BIT_STATE)
29 # define VKAPI_ATTR __attribute__((pcs("aapcs-vfp")))
34 #if (DE_OS == DE_OS_WIN32) && ((defined(_MSC_VER) && _MSC_VER >= 800) || defined(__MINGW32__) || defined(_STDCALL_SUPPORTED))
35 # define VKAPI_CALL __stdcall
40 #define VK_NULL_HANDLE DE_NULL
41 #define VK_DEFINE_HANDLE(NAME, TYPE) typedef struct NAME##_s* NAME
42 #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(NAME, TYPE) typedef Handle<TYPE> NAME
44 #define VK_DEFINE_PLATFORM_TYPE(NAME, COMPATIBLE) \
47 COMPATIBLE internal; \
48 explicit NAME (COMPATIBLE internal_) \
49 : internal(internal_) {} \
53 #define VK_MAKE_API_VERSION(VARIANT, MAJOR, MINOR, PATCH) \
54 ((((deUint32)(VARIANT)) << 29) | (((deUint32)(MAJOR)) << 22) | (((deUint32)(MINOR)) << 12) | ((deUint32)(PATCH)))
55 #define VKSC_API_VARIANT 1
56 #define VK_MAKE_VERSION(MAJOR, MINOR, PATCH) VK_MAKE_API_VERSION(0, MAJOR, MINOR, PATCH)
57 #define VK_BIT(NUM) (1u<<(deUint32)(NUM))
59 #define VK_API_VERSION_VARIANT(version) ((deUint32)(version) >> 29)
60 #define VK_API_VERSION_MAJOR(version) (((deUint32)(version) >> 22) & 0x7FU)
61 #define VK_API_VERSION_MINOR(version) (((deUint32)(version) >> 12) & 0x3FFU)
62 #define VK_API_VERSION_PATCH(version) ((deUint32)(version) & 0xFFFU)
64 #define VK_CHECK(EXPR) vk::checkResult((EXPR), #EXPR, __FILE__, __LINE__)
65 #define VK_CHECK_SUPPORTED(EXPR) vk::checkResultSupported((EXPR), #EXPR, __FILE__, __LINE__)
66 #define VK_CHECK_MSG(EXPR, MSG) vk::checkResult((EXPR), MSG, __FILE__, __LINE__)
67 #define VK_CHECK_WSI(EXPR) vk::checkWsiResult((EXPR), #EXPR, __FILE__, __LINE__)
69 #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \
70 ((((deUint32)(major)) << 22) | (((deUint32)(minor)) << 12) | ((deUint32)(patch)))
72 /*--------------------------------------------------------------------*//*!
73 * \brief Vulkan utilities
74 *//*--------------------------------------------------------------------*/
78 typedef deUint64 VkDeviceSize;
79 typedef deUint32 VkSampleMask;
80 typedef deUint32 VkBool32;
81 typedef deUint32 VkFlags;
82 typedef deUint64 VkFlags64;
83 typedef deUint64 VkDeviceAddress;
85 // enum HandleType { HANDLE_TYPE_INSTANCE, ... };
86 #include "vkHandleType.inl"
88 template<HandleType Type>
92 Handle (void) {} // \note Left uninitialized on purpose
93 Handle (deUint64 internal) : m_internal(internal) {}
95 Handle& operator= (deUint64 internal) { m_internal = internal; return *this; }
97 bool operator== (const Handle<Type>& other) const { return this->m_internal == other.m_internal; }
98 bool operator!= (const Handle<Type>& other) const { return this->m_internal != other.m_internal; }
100 bool operator! (void) const { return !m_internal; }
102 deUint64 getInternal (void) const { return m_internal; }
104 enum { HANDLE_TYPE = Type };
110 template<HandleType Type>
111 bool operator<(const Handle<Type>& lhs, const Handle<Type>& rhs)
113 return lhs.getInternal() < rhs.getInternal();
116 #include "vkBasicTypes.inl"
118 #define VK_CORE_FORMAT_LAST ((vk::VkFormat)(vk::VK_FORMAT_ASTC_12x12_SRGB_BLOCK+1))
119 #define VK_CORE_IMAGE_TILING_LAST ((vk::VkImageTiling)(vk::VK_IMAGE_TILING_LINEAR+1))
120 #define VK_CORE_IMAGE_TYPE_LAST ((vk::VkImageType)(vk::VK_IMAGE_TYPE_3D+1))
124 SPIRV_VERSION_1_0 = 0, //!< SPIR-V 1.0
125 SPIRV_VERSION_1_1 = 1, //!< SPIR-V 1.1
126 SPIRV_VERSION_1_2 = 2, //!< SPIR-V 1.2
127 SPIRV_VERSION_1_3 = 3, //!< SPIR-V 1.3
128 SPIRV_VERSION_1_4 = 4, //!< SPIR-V 1.4
129 SPIRV_VERSION_1_5 = 5, //!< SPIR-V 1.5
130 SPIRV_VERSION_1_6 = 6, //!< SPIR-V 1.6
162 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkVoidFunction) (void);
164 typedef VKAPI_ATTR void* (VKAPI_CALL* PFN_vkAllocationFunction) (void* pUserData,
167 VkSystemAllocationScope allocationScope);
168 typedef VKAPI_ATTR void* (VKAPI_CALL* PFN_vkReallocationFunction) (void* pUserData,
172 VkSystemAllocationScope allocationScope);
173 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkFreeFunction) (void* pUserData,
175 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkInternalAllocationNotification) (void* pUserData,
177 VkInternalAllocationType allocationType,
178 VkSystemAllocationScope allocationScope);
179 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkInternalFreeNotification) (void* pUserData,
181 VkInternalAllocationType allocationType,
182 VkSystemAllocationScope allocationScope);
184 #ifndef CTS_USES_VULKANSC
186 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL* PFN_vkDebugReportCallbackEXT) (VkDebugReportFlagsEXT flags,
187 VkDebugReportObjectTypeEXT objectType,
191 const char* pLayerPrefix,
192 const char* pMessage,
195 typedef VKAPI_ATTR PFN_vkVoidFunction (VKAPI_CALL* PFN_vkGetInstanceProcAddrLUNARG) (VkInstance instance, const char pName);
197 #endif // CTS_USES_VULKANSC
199 typedef VKAPI_ATTR VkBool32 (VKAPI_CALL *PFN_vkDebugUtilsMessengerCallbackEXT) (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
200 VkDebugUtilsMessageTypeFlagsEXT messageTypes,
201 const struct VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
204 typedef VKAPI_ATTR void (VKAPI_CALL* PFN_vkDeviceMemoryReportCallbackEXT) (const struct VkDeviceMemoryReportCallbackDataEXT* pCallbackData,
207 #ifdef CTS_USES_VULKANSC
209 typedef VKAPI_ATTR void (VKAPI_CALL *PFN_vkFaultCallbackFunction) (VkBool32 incompleteFaultData,
211 VkFaultData* pFaultData);
212 #endif // CTS_USES_VULKANSC
214 #include "vkStructTypes.inl"
216 #ifdef CTS_USES_VULKANSC
218 // substitute required enums and structs removed from VulkanSC specification
220 enum VkShaderModuleCreateFlagBits
222 VK_SHADER_MODULE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF,
224 typedef deUint32 VkShaderModuleCreateFlags;
226 #define VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO VkStructureType(16)
227 #define VK_OBJECT_TYPE_SHADER_MODULE VkObjectType(15)
229 struct VkShaderModuleCreateInfo
231 VkStructureType sType;
233 VkShaderModuleCreateFlags flags;
235 const deUint32* pCode;
238 #endif // CTS_USES_VULKANSC
240 typedef void* VkRemoteAddressNV;
244 #include "vkFunctionPointerTypes.inl"
247 class PlatformInterface
250 #include "vkVirtualPlatformInterface.inl"
252 virtual GetInstanceProcAddrFunc getGetInstanceProcAddr () const = 0;
255 PlatformInterface (void) {}
258 PlatformInterface (const PlatformInterface&);
259 PlatformInterface& operator= (const PlatformInterface&);
262 class InstanceInterface
265 #include "vkVirtualInstanceInterface.inl"
268 InstanceInterface (void) {}
271 InstanceInterface (const InstanceInterface&);
272 InstanceInterface& operator= (const InstanceInterface&);
275 class DeviceInterface
278 #include "vkVirtualDeviceInterface.inl"
280 #ifdef CTS_USES_VULKANSC
281 virtual VkResult createShaderModule (VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule) const = 0;
282 #endif // CTS_USES_VULKANSC
285 DeviceInterface (void) {}
288 DeviceInterface (const DeviceInterface&);
289 DeviceInterface& operator= (const DeviceInterface&);
292 class Error : public tcu::TestError
295 Error (VkResult error, const char* message, const char* expr, const char* file, int line);
296 Error (VkResult error, const std::string& message);
297 virtual ~Error (void) throw();
299 VkResult getError (void) const { return m_error; }
302 const VkResult m_error;
305 class NotSupportedError : public tcu::NotSupportedError
308 NotSupportedError (VkResult error, const char* message, const char* expr, const char* file, int line);
309 NotSupportedError (VkResult error, const std::string& message);
310 virtual ~NotSupportedError (void) throw();
312 VkResult getError (void) const { return m_error; }
315 const VkResult m_error;
318 class OutOfMemoryError : public tcu::ResourceError
321 OutOfMemoryError (VkResult error, const char* message, const char* expr, const char* file, int line);
322 OutOfMemoryError (VkResult error, const std::string& message);
323 virtual ~OutOfMemoryError (void) throw();
325 VkResult getError (void) const { return m_error; }
328 const VkResult m_error;
331 void checkResult (VkResult result, const char* message, const char* file, int line);
332 void checkResultSupported (VkResult result, const char* message, const char* file, int line);
333 void checkWsiResult (VkResult result, const char* message, const char* file, int line);
337 #endif // _VKDEFS_HPP