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