• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Null (dummy) Vulkan implementation.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vkNullDriver.hpp"
25 #include "vkPlatform.hpp"
26 #include "vkImageUtil.hpp"
27 #include "vkQueryUtil.hpp"
28 #include "tcuFunctionLibrary.hpp"
29 #include "deMemory.h"
30 
31 #if (DE_OS == DE_OS_ANDROID) && defined(__ANDROID_API_O__) && (DE_ANDROID_API >= __ANDROID_API_O__ /* __ANDROID_API_O__ */)
32 #	define USE_ANDROID_O_HARDWARE_BUFFER
33 #endif
34 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
35 #	include <android/hardware_buffer.h>
36 #endif
37 
38 #include <stdexcept>
39 #include <algorithm>
40 
41 namespace vk
42 {
43 
44 namespace
45 {
46 
47 using std::vector;
48 
49 // Memory management
50 
51 template<typename T>
allocateSystemMem(const VkAllocationCallbacks * pAllocator,VkSystemAllocationScope scope)52 void* allocateSystemMem (const VkAllocationCallbacks* pAllocator, VkSystemAllocationScope scope)
53 {
54 	void* ptr = pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(T), sizeof(void*), scope);
55 	if (!ptr)
56 		throw std::bad_alloc();
57 	return ptr;
58 }
59 
freeSystemMem(const VkAllocationCallbacks * pAllocator,void * mem)60 void freeSystemMem (const VkAllocationCallbacks* pAllocator, void* mem)
61 {
62 	pAllocator->pfnFree(pAllocator->pUserData, mem);
63 }
64 
65 template<typename Object, typename Handle, typename Parent, typename CreateInfo>
allocateHandle(Parent parent,const CreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator)66 Handle allocateHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
67 {
68 	Object* obj = DE_NULL;
69 
70 	if (pAllocator)
71 	{
72 		void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
73 		try
74 		{
75 			obj = new (mem) Object(parent, pCreateInfo);
76 			DE_ASSERT(obj == mem);
77 		}
78 		catch (...)
79 		{
80 			pAllocator->pfnFree(pAllocator->pUserData, mem);
81 			throw;
82 		}
83 	}
84 	else
85 		obj = new Object(parent, pCreateInfo);
86 
87 	return reinterpret_cast<Handle>(obj);
88 }
89 
90 template<typename Object, typename Handle, typename CreateInfo>
allocateHandle(const CreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator)91 Handle allocateHandle (const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
92 {
93 	Object* obj = DE_NULL;
94 
95 	if (pAllocator)
96 	{
97 		void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
98 		try
99 		{
100 			obj = new (mem) Object(pCreateInfo);
101 			DE_ASSERT(obj == mem);
102 		}
103 		catch (...)
104 		{
105 			pAllocator->pfnFree(pAllocator->pUserData, mem);
106 			throw;
107 		}
108 	}
109 	else
110 		obj = new Object(pCreateInfo);
111 
112 	return reinterpret_cast<Handle>(obj);
113 }
114 
115 template<typename Object, typename Handle, typename Parent>
allocateHandle(Parent parent,const VkAllocationCallbacks * pAllocator)116 Handle allocateHandle (Parent parent, const VkAllocationCallbacks* pAllocator)
117 {
118 	Object* obj = DE_NULL;
119 
120 	if (pAllocator)
121 	{
122 		void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
123 		try
124 		{
125 			obj = new (mem) Object(parent);
126 			DE_ASSERT(obj == mem);
127 		}
128 		catch (...)
129 		{
130 			pAllocator->pfnFree(pAllocator->pUserData, mem);
131 			throw;
132 		}
133 	}
134 	else
135 		obj = new Object(parent);
136 
137 	return reinterpret_cast<Handle>(obj);
138 }
139 
140 template<typename Object, typename Handle>
freeHandle(Handle handle,const VkAllocationCallbacks * pAllocator)141 void freeHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
142 {
143 	Object* obj = reinterpret_cast<Object*>(handle);
144 
145 	if (pAllocator)
146 	{
147 		obj->~Object();
148 		freeSystemMem(pAllocator, reinterpret_cast<void*>(obj));
149 	}
150 	else
151 		delete obj;
152 }
153 
154 template<typename Object, typename BaseObject, typename Handle, typename Parent, typename CreateInfo>
allocateNonDispHandle(Parent parent,const CreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator)155 Handle allocateNonDispHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
156 {
157 	Object* const	obj		= allocateHandle<Object, Object*>(parent, pCreateInfo, pAllocator);
158 	return Handle((deUint64)(deUintptr)static_cast<BaseObject*>(obj));
159 }
160 
161 template<typename Object, typename Handle, typename Parent, typename CreateInfo>
allocateNonDispHandle(Parent parent,const CreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator)162 Handle allocateNonDispHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
163 {
164 	return allocateNonDispHandle<Object, Object, Handle, Parent, CreateInfo>(parent, pCreateInfo, pAllocator);
165 }
166 
167 template<typename Object, typename Handle, typename Parent>
allocateNonDispHandle(Parent parent,const VkAllocationCallbacks * pAllocator)168 Handle allocateNonDispHandle (Parent parent, const VkAllocationCallbacks* pAllocator)
169 {
170 	Object* const	obj		= allocateHandle<Object, Object*>(parent, pAllocator);
171 	return Handle((deUint64)(deUintptr)obj);
172 }
173 
174 template<typename Object, typename Handle>
freeNonDispHandle(Handle handle,const VkAllocationCallbacks * pAllocator)175 void freeNonDispHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
176 {
177 	freeHandle<Object>(reinterpret_cast<Object*>((deUintptr)handle.getInternal()), pAllocator);
178 }
179 
180 // Object definitions
181 
182 #define VK_NULL_RETURN(STMT)					\
183 	do {										\
184 		try {									\
185 			STMT;								\
186 			return VK_SUCCESS;					\
187 		} catch (const std::bad_alloc&) {		\
188 			return VK_ERROR_OUT_OF_HOST_MEMORY;	\
189 		} catch (VkResult res) {				\
190 			return res;							\
191 		}										\
192 	} while (deGetFalse())
193 
194 // \todo [2015-07-14 pyry] Check FUNC type by checkedCastToPtr<T>() or similar
195 #define VK_NULL_FUNC_ENTRY(NAME, FUNC)	{ #NAME, (deFunctionPtr)FUNC }  // NOLINT(FUNC)
196 
197 #define VK_NULL_DEFINE_DEVICE_OBJ(NAME)				\
198 struct NAME											\
199 {													\
200 	NAME (VkDevice, const Vk##NAME##CreateInfo*) {}	\
201 }
202 
203 VK_NULL_DEFINE_DEVICE_OBJ(Fence);
204 VK_NULL_DEFINE_DEVICE_OBJ(Semaphore);
205 VK_NULL_DEFINE_DEVICE_OBJ(Event);
206 VK_NULL_DEFINE_DEVICE_OBJ(QueryPool);
207 VK_NULL_DEFINE_DEVICE_OBJ(BufferView);
208 VK_NULL_DEFINE_DEVICE_OBJ(ImageView);
209 VK_NULL_DEFINE_DEVICE_OBJ(ShaderModule);
210 VK_NULL_DEFINE_DEVICE_OBJ(PipelineCache);
211 VK_NULL_DEFINE_DEVICE_OBJ(PipelineLayout);
212 VK_NULL_DEFINE_DEVICE_OBJ(DescriptorSetLayout);
213 VK_NULL_DEFINE_DEVICE_OBJ(Sampler);
214 VK_NULL_DEFINE_DEVICE_OBJ(Framebuffer);
215 
216 class Instance
217 {
218 public:
219 										Instance		(const VkInstanceCreateInfo* instanceInfo);
~Instance(void)220 										~Instance		(void) {}
221 
getProcAddr(const char * name) const222 	PFN_vkVoidFunction					getProcAddr		(const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
223 
224 private:
225 	const tcu::StaticFunctionLibrary	m_functions;
226 };
227 
228 class SurfaceKHR
229 {
230 public:
SurfaceKHR(VkInstance,const VkXlibSurfaceCreateInfoKHR *)231 										SurfaceKHR		(VkInstance, const VkXlibSurfaceCreateInfoKHR*)		{}
SurfaceKHR(VkInstance,const VkXcbSurfaceCreateInfoKHR *)232 										SurfaceKHR		(VkInstance, const VkXcbSurfaceCreateInfoKHR*)		{}
SurfaceKHR(VkInstance,const VkWaylandSurfaceCreateInfoKHR *)233 										SurfaceKHR		(VkInstance, const VkWaylandSurfaceCreateInfoKHR*)	{}
SurfaceKHR(VkInstance,const VkAndroidSurfaceCreateInfoKHR *)234 										SurfaceKHR		(VkInstance, const VkAndroidSurfaceCreateInfoKHR*)	{}
SurfaceKHR(VkInstance,const VkWin32SurfaceCreateInfoKHR *)235 										SurfaceKHR		(VkInstance, const VkWin32SurfaceCreateInfoKHR*)	{}
SurfaceKHR(VkInstance,const VkDisplaySurfaceCreateInfoKHR *)236 										SurfaceKHR		(VkInstance, const VkDisplaySurfaceCreateInfoKHR*)	{}
SurfaceKHR(VkInstance,const VkViSurfaceCreateInfoNN *)237 										SurfaceKHR		(VkInstance, const VkViSurfaceCreateInfoNN*)		{}
SurfaceKHR(VkInstance,const VkIOSSurfaceCreateInfoMVK *)238 										SurfaceKHR		(VkInstance, const VkIOSSurfaceCreateInfoMVK*)		{}
SurfaceKHR(VkInstance,const VkMacOSSurfaceCreateInfoMVK *)239 										SurfaceKHR		(VkInstance, const VkMacOSSurfaceCreateInfoMVK*)	{}
SurfaceKHR(VkInstance,const VkImagePipeSurfaceCreateInfoFUCHSIA *)240 										SurfaceKHR		(VkInstance, const VkImagePipeSurfaceCreateInfoFUCHSIA*)	{}
SurfaceKHR(VkInstance,const VkHeadlessSurfaceCreateInfoEXT *)241 										SurfaceKHR		(VkInstance, const VkHeadlessSurfaceCreateInfoEXT*)	{}
SurfaceKHR(VkInstance,const VkStreamDescriptorSurfaceCreateInfoGGP *)242 										SurfaceKHR		(VkInstance, const VkStreamDescriptorSurfaceCreateInfoGGP*)	{}
SurfaceKHR(VkInstance,const VkMetalSurfaceCreateInfoEXT *)243 										SurfaceKHR		(VkInstance, const VkMetalSurfaceCreateInfoEXT*)	{}
~SurfaceKHR(void)244 										~SurfaceKHR		(void)												{}
245 };
246 
247 class DisplayModeKHR
248 {
249 public:
DisplayModeKHR(VkDisplayKHR,const VkDisplayModeCreateInfoKHR *)250 										DisplayModeKHR	(VkDisplayKHR, const VkDisplayModeCreateInfoKHR*) {}
~DisplayModeKHR(void)251 										~DisplayModeKHR	(void) {}
252 };
253 
254 class DebugReportCallbackEXT
255 {
256 public:
DebugReportCallbackEXT(VkInstance,const VkDebugReportCallbackCreateInfoEXT *)257 										DebugReportCallbackEXT	(VkInstance, const VkDebugReportCallbackCreateInfoEXT*) {}
~DebugReportCallbackEXT(void)258 										~DebugReportCallbackEXT	(void) {}
259 };
260 
261 class CuModuleNVX
262 {
263 public:
CuModuleNVX(VkDevice,const VkCuModuleCreateInfoNVX *)264 										CuModuleNVX	(VkDevice, const VkCuModuleCreateInfoNVX*) {}
~CuModuleNVX(void)265 										~CuModuleNVX(void) {}
266 };
267 
268 class CuFunctionNVX
269 {
270 public:
CuFunctionNVX(VkDevice,const VkCuFunctionCreateInfoNVX *)271 										CuFunctionNVX(VkDevice, const VkCuFunctionCreateInfoNVX*) {}
~CuFunctionNVX(void)272 										~CuFunctionNVX(void) {}
273 };
274 
275 class Device
276 {
277 public:
278 										Device			(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* deviceInfo);
~Device(void)279 										~Device			(void) {}
280 
getProcAddr(const char * name) const281 	PFN_vkVoidFunction					getProcAddr		(const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
282 
283 private:
284 	const tcu::StaticFunctionLibrary	m_functions;
285 };
286 
287 class Pipeline
288 {
289 public:
Pipeline(VkDevice,const VkGraphicsPipelineCreateInfo *)290 	Pipeline (VkDevice, const VkGraphicsPipelineCreateInfo*) {}
Pipeline(VkDevice,const VkComputePipelineCreateInfo *)291 	Pipeline (VkDevice, const VkComputePipelineCreateInfo*) {}
Pipeline(VkDevice,const VkRayTracingPipelineCreateInfoNV *)292 	Pipeline (VkDevice, const VkRayTracingPipelineCreateInfoNV*) {}
Pipeline(VkDevice,const VkRayTracingPipelineCreateInfoKHR *)293 	Pipeline (VkDevice, const VkRayTracingPipelineCreateInfoKHR*) {}
294 };
295 
296 class RenderPass
297 {
298 public:
RenderPass(VkDevice,const VkRenderPassCreateInfo *)299 	RenderPass (VkDevice, const VkRenderPassCreateInfo*)		{}
RenderPass(VkDevice,const VkRenderPassCreateInfo2 *)300 	RenderPass (VkDevice, const VkRenderPassCreateInfo2*)		{}
301 };
302 
303 class SwapchainKHR
304 {
305 public:
SwapchainKHR(VkDevice,const VkSwapchainCreateInfoKHR *)306 										SwapchainKHR	(VkDevice, const VkSwapchainCreateInfoKHR*) {}
~SwapchainKHR(void)307 										~SwapchainKHR	(void) {}
308 };
309 
310 class SamplerYcbcrConversion
311 {
312 public:
SamplerYcbcrConversion(VkDevice,const VkSamplerYcbcrConversionCreateInfo *)313 	SamplerYcbcrConversion (VkDevice, const VkSamplerYcbcrConversionCreateInfo*) {}
314 };
315 
316 class Buffer
317 {
318 public:
Buffer(VkDevice,const VkBufferCreateInfo * pCreateInfo)319 						Buffer		(VkDevice, const VkBufferCreateInfo* pCreateInfo)
320 		: m_size (pCreateInfo->size)
321 	{
322 	}
323 
getSize(void) const324 	VkDeviceSize		getSize		(void) const { return m_size;	}
325 
326 private:
327 	const VkDeviceSize	m_size;
328 };
329 
getExternalTypesHandle(const VkImageCreateInfo * pCreateInfo)330 VkExternalMemoryHandleTypeFlags getExternalTypesHandle (const VkImageCreateInfo* pCreateInfo)
331 {
332 	const VkExternalMemoryImageCreateInfo* const	externalInfo	= findStructure<VkExternalMemoryImageCreateInfo>	(pCreateInfo->pNext);
333 
334 	return externalInfo ? externalInfo->handleTypes : 0u;
335 }
336 
337 class Image
338 {
339 public:
Image(VkDevice,const VkImageCreateInfo * pCreateInfo)340 												Image					(VkDevice, const VkImageCreateInfo* pCreateInfo)
341 		: m_imageType			(pCreateInfo->imageType)
342 		, m_format				(pCreateInfo->format)
343 		, m_extent				(pCreateInfo->extent)
344 		, m_arrayLayers			(pCreateInfo->arrayLayers)
345 		, m_samples				(pCreateInfo->samples)
346 		, m_usage				(pCreateInfo->usage)
347 		, m_flags				(pCreateInfo->flags)
348 		, m_externalHandleTypes	(getExternalTypesHandle(pCreateInfo))
349 	{
350 	}
351 
getImageType(void) const352 	VkImageType									getImageType			(void) const { return m_imageType;				}
getFormat(void) const353 	VkFormat									getFormat				(void) const { return m_format;					}
getExtent(void) const354 	VkExtent3D									getExtent				(void) const { return m_extent;					}
getArrayLayers(void) const355 	deUint32									getArrayLayers			(void) const { return m_arrayLayers;			}
getSamples(void) const356 	VkSampleCountFlagBits						getSamples				(void) const { return m_samples;				}
getUsage(void) const357 	VkImageUsageFlags							getUsage				(void) const { return m_usage;					}
getFlags(void) const358 	VkImageCreateFlags							getFlags				(void) const { return m_flags;					}
getExternalHandleTypes(void) const359 	VkExternalMemoryHandleTypeFlags				getExternalHandleTypes	(void) const { return m_externalHandleTypes;	}
360 
361 private:
362 	const VkImageType							m_imageType;
363 	const VkFormat								m_format;
364 	const VkExtent3D							m_extent;
365 	const deUint32								m_arrayLayers;
366 	const VkSampleCountFlagBits					m_samples;
367 	const VkImageUsageFlags						m_usage;
368 	const VkImageCreateFlags					m_flags;
369 	const VkExternalMemoryHandleTypeFlags		m_externalHandleTypes;
370 };
371 
allocateHeap(const VkMemoryAllocateInfo * pAllocInfo)372 void* allocateHeap (const VkMemoryAllocateInfo* pAllocInfo)
373 {
374 	// \todo [2015-12-03 pyry] Alignment requirements?
375 	// \todo [2015-12-03 pyry] Empty allocations okay?
376 	if (pAllocInfo->allocationSize > 0)
377 	{
378 		void* const heapPtr = deMalloc((size_t)pAllocInfo->allocationSize);
379 		if (!heapPtr)
380 			throw std::bad_alloc();
381 		return heapPtr;
382 	}
383 	else
384 		return DE_NULL;
385 }
386 
freeHeap(void * ptr)387 void freeHeap (void* ptr)
388 {
389 	deFree(ptr);
390 }
391 
392 class DeviceMemory
393 {
394 public:
~DeviceMemory(void)395 	virtual			~DeviceMemory	(void) {}
396 	virtual void*	map				(void) = 0;
397 	virtual void	unmap			(void) = 0;
398 };
399 
400 class PrivateDeviceMemory : public DeviceMemory
401 {
402 public:
PrivateDeviceMemory(VkDevice,const VkMemoryAllocateInfo * pAllocInfo)403 						PrivateDeviceMemory		(VkDevice, const VkMemoryAllocateInfo* pAllocInfo)
404 		: m_memory(allocateHeap(pAllocInfo))
405 	{
406 		// \todo [2016-08-03 pyry] In some cases leaving data unintialized would help valgrind analysis,
407 		//						   but currently it mostly hinders it.
408 		if (m_memory)
409 			deMemset(m_memory, 0xcd, (size_t)pAllocInfo->allocationSize);
410 	}
~PrivateDeviceMemory(void)411 	virtual				~PrivateDeviceMemory	(void)
412 	{
413 		freeHeap(m_memory);
414 	}
415 
map(void)416 	virtual void*		map						(void) /*override*/ { return m_memory; }
unmap(void)417 	virtual void		unmap					(void) /*override*/ {}
418 
419 private:
420 	void* const			m_memory;
421 };
422 
423 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
findOrCreateHwBuffer(const VkMemoryAllocateInfo * pAllocInfo)424 AHardwareBuffer* findOrCreateHwBuffer (const VkMemoryAllocateInfo* pAllocInfo)
425 {
426 	const VkExportMemoryAllocateInfo* const					exportInfo		= findStructure<VkExportMemoryAllocateInfo>(pAllocInfo->pNext);
427 	const VkImportAndroidHardwareBufferInfoANDROID* const	importInfo		= findStructure<VkImportAndroidHardwareBufferInfoANDROID>(pAllocInfo->pNext);
428 	const VkMemoryDedicatedAllocateInfo* const				dedicatedInfo	= findStructure<VkMemoryDedicatedAllocateInfo>(pAllocInfo->pNext);
429 	const Image* const										image			= dedicatedInfo && !!dedicatedInfo->image ? reinterpret_cast<const Image*>(dedicatedInfo->image.getInternal()) : DE_NULL;
430 	AHardwareBuffer*										hwbuffer		= DE_NULL;
431 
432 	// Import and export aren't mutually exclusive; we can have both simultaneously.
433 	DE_ASSERT((importInfo && importInfo->buffer.internal) ||
434 		(exportInfo && (exportInfo->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) != 0));
435 
436 	if (importInfo && importInfo->buffer.internal)
437 	{
438 		hwbuffer = (AHardwareBuffer*)importInfo->buffer.internal;
439 		AHardwareBuffer_acquire(hwbuffer);
440 	}
441 	else if (exportInfo && (exportInfo->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) != 0)
442 	{
443 		AHardwareBuffer_Desc hwbufferDesc;
444 		deMemset(&hwbufferDesc, 0, sizeof(hwbufferDesc));
445 
446 		if (image)
447 		{
448 			hwbufferDesc.width	= image->getExtent().width;
449 			hwbufferDesc.height	= image->getExtent().height;
450 			hwbufferDesc.layers = image->getArrayLayers();
451 			switch (image->getFormat())
452 			{
453 				case VK_FORMAT_R8G8B8A8_UNORM:
454 					hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
455 					break;
456 				case VK_FORMAT_R8G8B8_UNORM:
457 					hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM;
458 					break;
459 				case VK_FORMAT_R5G6B5_UNORM_PACK16:
460 					hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
461 					break;
462 				case VK_FORMAT_R16G16B16A16_SFLOAT:
463 					hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
464 					break;
465 				case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
466 					hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
467 					break;
468 				default:
469 					DE_FATAL("Unsupported image format for Android hardware buffer export");
470 					break;
471 			}
472 			if ((image->getUsage() & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
473 				hwbufferDesc.usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
474 			if ((image->getUsage() & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0)
475 				hwbufferDesc.usage |= AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
476 			// if ((image->getFlags() & VK_IMAGE_CREATE_PROTECTED_BIT) != 0)
477 			//	hwbufferDesc.usage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
478 
479 			// Make sure we have at least one AHB GPU usage, even if the image doesn't have any
480 			// Vulkan usages with corresponding to AHB GPU usages.
481 			if ((image->getUsage() & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) == 0)
482 				hwbufferDesc.usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
483 		}
484 		else
485 		{
486 			hwbufferDesc.width = static_cast<deUint32>(pAllocInfo->allocationSize);
487 			hwbufferDesc.height = 1,
488 			hwbufferDesc.layers = 1,
489 			hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_BLOB,
490 			hwbufferDesc.usage = AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER;
491 		}
492 
493 		AHardwareBuffer_allocate(&hwbufferDesc, &hwbuffer);
494 	}
495 
496 	return hwbuffer;
497 }
498 
499 class ExternalDeviceMemoryAndroid : public DeviceMemory
500 {
501 public:
ExternalDeviceMemoryAndroid(VkDevice,const VkMemoryAllocateInfo * pAllocInfo)502 						ExternalDeviceMemoryAndroid		(VkDevice, const VkMemoryAllocateInfo* pAllocInfo)
503 		: m_hwbuffer(findOrCreateHwBuffer(pAllocInfo))
504 	{}
~ExternalDeviceMemoryAndroid(void)505 	virtual				~ExternalDeviceMemoryAndroid	(void)
506 	{
507 		if (m_hwbuffer)
508 			AHardwareBuffer_release(m_hwbuffer);
509 	}
510 
map(void)511 	virtual void*		map								(void) /*override*/
512 	{
513 		void* p;
514 		AHardwareBuffer_lock(m_hwbuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1, NULL, &p);
515 		return p;
516 	}
517 
unmap(void)518 	virtual void		unmap							(void) /*override*/ { AHardwareBuffer_unlock(m_hwbuffer, NULL); }
519 
getHwBuffer(void)520 	AHardwareBuffer*	getHwBuffer						(void)				{ return m_hwbuffer;						}
521 
522 private:
523 	AHardwareBuffer* const	m_hwbuffer;
524 };
525 #endif // defined(USE_ANDROID_O_HARDWARE_BUFFER)
526 
527 class IndirectCommandsLayoutNV
528 {
529 public:
IndirectCommandsLayoutNV(VkDevice,const VkIndirectCommandsLayoutCreateInfoNV *)530 						IndirectCommandsLayoutNV	(VkDevice, const VkIndirectCommandsLayoutCreateInfoNV*)
531 						{}
532 };
533 
534 class DebugUtilsMessengerEXT
535 {
536 public:
DebugUtilsMessengerEXT(VkInstance,const VkDebugUtilsMessengerCreateInfoEXT *)537 						DebugUtilsMessengerEXT		(VkInstance, const VkDebugUtilsMessengerCreateInfoEXT*)
538 						{}
539 };
540 
541 class AccelerationStructureNV
542 {
543 public:
AccelerationStructureNV(VkDevice,const VkAccelerationStructureCreateInfoNV *)544 						AccelerationStructureNV		(VkDevice, const VkAccelerationStructureCreateInfoNV*)
545 						{}
546 };
547 
548 class AccelerationStructureKHR
549 {
550 public:
AccelerationStructureKHR(VkDevice,const VkAccelerationStructureCreateInfoKHR *)551 						AccelerationStructureKHR	(VkDevice, const VkAccelerationStructureCreateInfoKHR*)
552 						{}
553 };
554 
555 class DeferredOperationKHR
556 {
557 public:
DeferredOperationKHR(VkDevice)558 						DeferredOperationKHR		(VkDevice)
559 						{}
560 };
561 
562 class VideoSessionKHR
563 {
564 public:
VideoSessionKHR(VkDevice,const VkVideoSessionCreateInfoKHR *)565 						VideoSessionKHR				(VkDevice, const VkVideoSessionCreateInfoKHR*)
566 						{}
567 };
568 
569 class VideoSessionParametersKHR
570 {
571 public:
VideoSessionParametersKHR(VkDevice,const VkVideoSessionParametersCreateInfoKHR *)572 						VideoSessionParametersKHR	(VkDevice, const VkVideoSessionParametersCreateInfoKHR*)
573 						{}
574 };
575 
576 class ValidationCacheEXT
577 {
578 public:
ValidationCacheEXT(VkDevice,const VkValidationCacheCreateInfoEXT *)579 						ValidationCacheEXT			(VkDevice, const VkValidationCacheCreateInfoEXT*)
580 						{}
581 };
582 
583 class CommandBuffer
584 {
585 public:
CommandBuffer(VkDevice,VkCommandPool,VkCommandBufferLevel)586 						CommandBuffer				(VkDevice, VkCommandPool, VkCommandBufferLevel)
587 						{}
588 };
589 
590 class DescriptorUpdateTemplate
591 {
592 public:
DescriptorUpdateTemplate(VkDevice,const VkDescriptorUpdateTemplateCreateInfo *)593 						DescriptorUpdateTemplate	(VkDevice, const VkDescriptorUpdateTemplateCreateInfo*)
594 						{}
595 };
596 
597 class PrivateDataSlotEXT
598 {
599 public:
PrivateDataSlotEXT(VkDevice,const VkPrivateDataSlotCreateInfoEXT *)600 						PrivateDataSlotEXT			(VkDevice, const VkPrivateDataSlotCreateInfoEXT*)
601 						{}
602 };
603 
604 class BufferCollectionFUCHSIA
605 {
606 public:
BufferCollectionFUCHSIA(VkDevice,const VkBufferCollectionCreateInfoFUCHSIA *)607 						BufferCollectionFUCHSIA		(VkDevice, const VkBufferCollectionCreateInfoFUCHSIA*)
608 						{}
609 };
610 
611 class CommandPool
612 {
613 public:
CommandPool(VkDevice device,const VkCommandPoolCreateInfo *)614 										CommandPool		(VkDevice device, const VkCommandPoolCreateInfo*)
615 											: m_device(device)
616 										{}
617 										~CommandPool	(void);
618 
619 	VkCommandBuffer						allocate		(VkCommandBufferLevel level);
620 	void								free			(VkCommandBuffer buffer);
621 
622 private:
623 	const VkDevice						m_device;
624 
625 	vector<CommandBuffer*>				m_buffers;
626 };
627 
~CommandPool(void)628 CommandPool::~CommandPool (void)
629 {
630 	for (size_t ndx = 0; ndx < m_buffers.size(); ++ndx)
631 		delete m_buffers[ndx];
632 }
633 
allocate(VkCommandBufferLevel level)634 VkCommandBuffer CommandPool::allocate (VkCommandBufferLevel level)
635 {
636 	CommandBuffer* const	impl	= new CommandBuffer(m_device, VkCommandPool(reinterpret_cast<deUintptr>(this)), level);
637 
638 	try
639 	{
640 		m_buffers.push_back(impl);
641 	}
642 	catch (...)
643 	{
644 		delete impl;
645 		throw;
646 	}
647 
648 	return reinterpret_cast<VkCommandBuffer>(impl);
649 }
650 
free(VkCommandBuffer buffer)651 void CommandPool::free (VkCommandBuffer buffer)
652 {
653 	CommandBuffer* const	impl	= reinterpret_cast<CommandBuffer*>(buffer);
654 
655 	for (size_t ndx = 0; ndx < m_buffers.size(); ++ndx)
656 	{
657 		if (m_buffers[ndx] == impl)
658 		{
659 			std::swap(m_buffers[ndx], m_buffers.back());
660 			m_buffers.pop_back();
661 			delete impl;
662 			return;
663 		}
664 	}
665 
666 	DE_FATAL("VkCommandBuffer not owned by VkCommandPool");
667 }
668 
669 class DescriptorSet
670 {
671 public:
DescriptorSet(VkDevice,VkDescriptorPool,VkDescriptorSetLayout)672 	DescriptorSet (VkDevice, VkDescriptorPool, VkDescriptorSetLayout) {}
673 };
674 
675 class DescriptorPool
676 {
677 public:
DescriptorPool(VkDevice device,const VkDescriptorPoolCreateInfo * pCreateInfo)678 										DescriptorPool	(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo)
679 											: m_device	(device)
680 											, m_flags	(pCreateInfo->flags)
681 										{}
~DescriptorPool(void)682 										~DescriptorPool	(void)
683 										{
684 											reset();
685 										}
686 
687 	VkDescriptorSet						allocate		(VkDescriptorSetLayout setLayout);
688 	void								free			(VkDescriptorSet set);
689 
690 	void								reset			(void);
691 
692 private:
693 	const VkDevice						m_device;
694 	const VkDescriptorPoolCreateFlags	m_flags;
695 
696 	vector<DescriptorSet*>				m_managedSets;
697 };
698 
allocate(VkDescriptorSetLayout setLayout)699 VkDescriptorSet DescriptorPool::allocate (VkDescriptorSetLayout setLayout)
700 {
701 	DescriptorSet* const	impl	= new DescriptorSet(m_device, VkDescriptorPool(reinterpret_cast<deUintptr>(this)), setLayout);
702 
703 	try
704 	{
705 		m_managedSets.push_back(impl);
706 	}
707 	catch (...)
708 	{
709 		delete impl;
710 		throw;
711 	}
712 
713 	return VkDescriptorSet(reinterpret_cast<deUintptr>(impl));
714 }
715 
free(VkDescriptorSet set)716 void DescriptorPool::free (VkDescriptorSet set)
717 {
718 	DescriptorSet* const	impl	= reinterpret_cast<DescriptorSet*>((deUintptr)set.getInternal());
719 
720 	DE_ASSERT(m_flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT);
721 	DE_UNREF(m_flags);
722 
723 	for (size_t ndx = 0; ndx < m_managedSets.size(); ++ndx)
724 	{
725 		if (m_managedSets[ndx] == impl)
726 		{
727 			std::swap(m_managedSets[ndx], m_managedSets.back());
728 			m_managedSets.pop_back();
729 			delete impl;
730 			return;
731 		}
732 	}
733 
734 	DE_FATAL("VkDescriptorSet not owned by VkDescriptorPool");
735 }
736 
reset(void)737 void DescriptorPool::reset (void)
738 {
739 	for (size_t ndx = 0; ndx < m_managedSets.size(); ++ndx)
740 		delete m_managedSets[ndx];
741 	m_managedSets.clear();
742 }
743 
744 // API implementation
745 
746 extern "C"
747 {
748 
getDeviceProcAddr(VkDevice device,const char * pName)749 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getDeviceProcAddr (VkDevice device, const char* pName)
750 {
751 	return reinterpret_cast<Device*>(device)->getProcAddr(pName);
752 }
753 
createGraphicsPipelines(VkDevice device,VkPipelineCache,deUint32 count,const VkGraphicsPipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines)754 VKAPI_ATTR VkResult VKAPI_CALL createGraphicsPipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
755 {
756 	deUint32 allocNdx;
757 	try
758 	{
759 		for (allocNdx = 0; allocNdx < count; allocNdx++)
760 			pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
761 
762 		return VK_SUCCESS;
763 	}
764 	catch (const std::bad_alloc&)
765 	{
766 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
767 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
768 
769 		return VK_ERROR_OUT_OF_HOST_MEMORY;
770 	}
771 	catch (VkResult err)
772 	{
773 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
774 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
775 
776 		return err;
777 	}
778 }
779 
createComputePipelines(VkDevice device,VkPipelineCache,deUint32 count,const VkComputePipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines)780 VKAPI_ATTR VkResult VKAPI_CALL createComputePipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
781 {
782 	deUint32 allocNdx;
783 	try
784 	{
785 		for (allocNdx = 0; allocNdx < count; allocNdx++)
786 			pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
787 
788 		return VK_SUCCESS;
789 	}
790 	catch (const std::bad_alloc&)
791 	{
792 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
793 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
794 
795 		return VK_ERROR_OUT_OF_HOST_MEMORY;
796 	}
797 	catch (VkResult err)
798 	{
799 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
800 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
801 
802 		return err;
803 	}
804 }
805 
createRayTracingPipelinesNV(VkDevice device,VkPipelineCache,deUint32 count,const VkRayTracingPipelineCreateInfoKHR * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines)806 VKAPI_ATTR VkResult VKAPI_CALL createRayTracingPipelinesNV (VkDevice device, VkPipelineCache, deUint32 count, const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
807 {
808 	deUint32 allocNdx;
809 	try
810 	{
811 		for (allocNdx = 0; allocNdx < count; allocNdx++)
812 			pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
813 
814 		return VK_SUCCESS;
815 	}
816 	catch (const std::bad_alloc&)
817 	{
818 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
819 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
820 
821 		return VK_ERROR_OUT_OF_HOST_MEMORY;
822 	}
823 	catch (VkResult err)
824 	{
825 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
826 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
827 
828 		return err;
829 	}
830 }
831 
createRayTracingPipelinesKHR(VkDevice device,VkPipelineCache,deUint32 count,const VkRayTracingPipelineCreateInfoKHR * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines)832 VKAPI_ATTR VkResult VKAPI_CALL createRayTracingPipelinesKHR (VkDevice device, VkPipelineCache, deUint32 count, const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
833 {
834 	deUint32 allocNdx;
835 	try
836 	{
837 		for (allocNdx = 0; allocNdx < count; allocNdx++)
838 			pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
839 
840 		return VK_SUCCESS;
841 	}
842 	catch (const std::bad_alloc&)
843 	{
844 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
845 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
846 
847 		return VK_ERROR_OUT_OF_HOST_MEMORY;
848 	}
849 	catch (VkResult err)
850 	{
851 		for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
852 			freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
853 
854 		return err;
855 	}
856 }
857 
enumeratePhysicalDevices(VkInstance,deUint32 * pPhysicalDeviceCount,VkPhysicalDevice * pDevices)858 VKAPI_ATTR VkResult VKAPI_CALL enumeratePhysicalDevices (VkInstance, deUint32* pPhysicalDeviceCount, VkPhysicalDevice* pDevices)
859 {
860 	if (pDevices && *pPhysicalDeviceCount >= 1u)
861 		*pDevices = reinterpret_cast<VkPhysicalDevice>((void*)(deUintptr)1u);
862 
863 	*pPhysicalDeviceCount = 1;
864 
865 	return VK_SUCCESS;
866 }
867 
enumerateExtensions(deUint32 numExtensions,const VkExtensionProperties * extensions,deUint32 * pPropertyCount,VkExtensionProperties * pProperties)868 VkResult enumerateExtensions (deUint32 numExtensions, const VkExtensionProperties* extensions, deUint32* pPropertyCount, VkExtensionProperties* pProperties)
869 {
870 	const deUint32	dstSize		= pPropertyCount ? *pPropertyCount : 0;
871 
872 	if (pPropertyCount)
873 		*pPropertyCount = numExtensions;
874 
875 	if (pProperties)
876 	{
877 		for (deUint32 ndx = 0; ndx < de::min(numExtensions, dstSize); ++ndx)
878 			pProperties[ndx] = extensions[ndx];
879 
880 		if (dstSize < numExtensions)
881 			return VK_INCOMPLETE;
882 	}
883 
884 	return VK_SUCCESS;
885 }
886 
enumerateInstanceExtensionProperties(const char * pLayerName,deUint32 * pPropertyCount,VkExtensionProperties * pProperties)887 VKAPI_ATTR VkResult VKAPI_CALL enumerateInstanceExtensionProperties (const char* pLayerName, deUint32* pPropertyCount, VkExtensionProperties* pProperties)
888 {
889 	static const VkExtensionProperties	s_extensions[]	=
890 	{
891 		{ "VK_KHR_get_physical_device_properties2", 1u },
892 		{ "VK_KHR_external_memory_capabilities",	1u },
893 	};
894 
895 	if (!pLayerName)
896 		return enumerateExtensions((deUint32)DE_LENGTH_OF_ARRAY(s_extensions), s_extensions, pPropertyCount, pProperties);
897 	else
898 		return enumerateExtensions(0, DE_NULL, pPropertyCount, pProperties);
899 }
900 
enumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,deUint32 * pPropertyCount,VkExtensionProperties * pProperties)901 VKAPI_ATTR VkResult VKAPI_CALL enumerateDeviceExtensionProperties (VkPhysicalDevice physicalDevice, const char* pLayerName, deUint32* pPropertyCount, VkExtensionProperties* pProperties)
902 {
903 	DE_UNREF(physicalDevice);
904 
905 	static const VkExtensionProperties	s_extensions[]	=
906 	{
907 		{ "VK_KHR_bind_memory2",								1u },
908 		{ "VK_KHR_external_memory",							    1u },
909 		{ "VK_KHR_get_memory_requirements2",					1u },
910 		{ "VK_KHR_maintenance1",								1u },
911 		{ "VK_KHR_sampler_ycbcr_conversion",					1u },
912 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
913 		{ "VK_ANDROID_external_memory_android_hardware_buffer",	1u },
914 #endif
915 	};
916 
917 	if (!pLayerName)
918 		return enumerateExtensions((deUint32)DE_LENGTH_OF_ARRAY(s_extensions), s_extensions, pPropertyCount, pProperties);
919 	else
920 		return enumerateExtensions(0, DE_NULL, pPropertyCount, pProperties);
921 }
922 
getPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,VkPhysicalDeviceFeatures * pFeatures)923 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceFeatures (VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
924 {
925 	DE_UNREF(physicalDevice);
926 
927 	// Enable all features allow as many tests to run as possible
928 	pFeatures->robustBufferAccess							= VK_TRUE;
929 	pFeatures->fullDrawIndexUint32							= VK_TRUE;
930 	pFeatures->imageCubeArray								= VK_TRUE;
931 	pFeatures->independentBlend								= VK_TRUE;
932 	pFeatures->geometryShader								= VK_TRUE;
933 	pFeatures->tessellationShader							= VK_TRUE;
934 	pFeatures->sampleRateShading							= VK_TRUE;
935 	pFeatures->dualSrcBlend									= VK_TRUE;
936 	pFeatures->logicOp										= VK_TRUE;
937 	pFeatures->multiDrawIndirect							= VK_TRUE;
938 	pFeatures->drawIndirectFirstInstance					= VK_TRUE;
939 	pFeatures->depthClamp									= VK_TRUE;
940 	pFeatures->depthBiasClamp								= VK_TRUE;
941 	pFeatures->fillModeNonSolid								= VK_TRUE;
942 	pFeatures->depthBounds									= VK_TRUE;
943 	pFeatures->wideLines									= VK_TRUE;
944 	pFeatures->largePoints									= VK_TRUE;
945 	pFeatures->alphaToOne									= VK_TRUE;
946 	pFeatures->multiViewport								= VK_TRUE;
947 	pFeatures->samplerAnisotropy							= VK_TRUE;
948 	pFeatures->textureCompressionETC2						= VK_TRUE;
949 	pFeatures->textureCompressionASTC_LDR					= VK_TRUE;
950 	pFeatures->textureCompressionBC							= VK_TRUE;
951 	pFeatures->occlusionQueryPrecise						= VK_TRUE;
952 	pFeatures->pipelineStatisticsQuery						= VK_TRUE;
953 	pFeatures->vertexPipelineStoresAndAtomics				= VK_TRUE;
954 	pFeatures->fragmentStoresAndAtomics						= VK_TRUE;
955 	pFeatures->shaderTessellationAndGeometryPointSize		= VK_TRUE;
956 	pFeatures->shaderImageGatherExtended					= VK_TRUE;
957 	pFeatures->shaderStorageImageExtendedFormats			= VK_TRUE;
958 	pFeatures->shaderStorageImageMultisample				= VK_TRUE;
959 	pFeatures->shaderStorageImageReadWithoutFormat			= VK_TRUE;
960 	pFeatures->shaderStorageImageWriteWithoutFormat			= VK_TRUE;
961 	pFeatures->shaderUniformBufferArrayDynamicIndexing		= VK_TRUE;
962 	pFeatures->shaderSampledImageArrayDynamicIndexing		= VK_TRUE;
963 	pFeatures->shaderStorageBufferArrayDynamicIndexing		= VK_TRUE;
964 	pFeatures->shaderStorageImageArrayDynamicIndexing		= VK_TRUE;
965 	pFeatures->shaderClipDistance							= VK_TRUE;
966 	pFeatures->shaderCullDistance							= VK_TRUE;
967 	pFeatures->shaderFloat64								= VK_TRUE;
968 	pFeatures->shaderInt64									= VK_TRUE;
969 	pFeatures->shaderInt16									= VK_TRUE;
970 	pFeatures->shaderResourceResidency						= VK_TRUE;
971 	pFeatures->shaderResourceMinLod							= VK_TRUE;
972 	pFeatures->sparseBinding								= VK_TRUE;
973 	pFeatures->sparseResidencyBuffer						= VK_TRUE;
974 	pFeatures->sparseResidencyImage2D						= VK_TRUE;
975 	pFeatures->sparseResidencyImage3D						= VK_TRUE;
976 	pFeatures->sparseResidency2Samples						= VK_TRUE;
977 	pFeatures->sparseResidency4Samples						= VK_TRUE;
978 	pFeatures->sparseResidency8Samples						= VK_TRUE;
979 	pFeatures->sparseResidency16Samples						= VK_TRUE;
980 	pFeatures->sparseResidencyAliased						= VK_TRUE;
981 	pFeatures->variableMultisampleRate						= VK_TRUE;
982 	pFeatures->inheritedQueries								= VK_TRUE;
983 }
984 
getPhysicalDeviceProperties(VkPhysicalDevice,VkPhysicalDeviceProperties * props)985 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceProperties (VkPhysicalDevice, VkPhysicalDeviceProperties* props)
986 {
987 	deMemset(props, 0, sizeof(VkPhysicalDeviceProperties));
988 
989 	props->apiVersion		= VK_API_VERSION_1_1;
990 	props->driverVersion	= 1u;
991 	props->deviceType		= VK_PHYSICAL_DEVICE_TYPE_OTHER;
992 
993 	deMemcpy(props->deviceName, "null", 5);
994 
995 	// Spec minmax
996 	props->limits.maxImageDimension1D									= 4096;
997 	props->limits.maxImageDimension2D									= 4096;
998 	props->limits.maxImageDimension3D									= 256;
999 	props->limits.maxImageDimensionCube									= 4096;
1000 	props->limits.maxImageArrayLayers									= 256;
1001 	props->limits.maxTexelBufferElements								= 65536;
1002 	props->limits.maxUniformBufferRange									= 16384;
1003 	props->limits.maxStorageBufferRange									= 1u<<27;
1004 	props->limits.maxPushConstantsSize									= 128;
1005 	props->limits.maxMemoryAllocationCount								= 4096;
1006 	props->limits.maxSamplerAllocationCount								= 4000;
1007 	props->limits.bufferImageGranularity								= 131072;
1008 	props->limits.sparseAddressSpaceSize								= 1u<<31;
1009 	props->limits.maxBoundDescriptorSets								= 4;
1010 	props->limits.maxPerStageDescriptorSamplers							= 16;
1011 	props->limits.maxPerStageDescriptorUniformBuffers					= 12;
1012 	props->limits.maxPerStageDescriptorStorageBuffers					= 4;
1013 	props->limits.maxPerStageDescriptorSampledImages					= 16;
1014 	props->limits.maxPerStageDescriptorStorageImages					= 4;
1015 	props->limits.maxPerStageDescriptorInputAttachments					= 4;
1016 	props->limits.maxPerStageResources									= 128;
1017 	props->limits.maxDescriptorSetSamplers								= 96;
1018 	props->limits.maxDescriptorSetUniformBuffers						= 72;
1019 	props->limits.maxDescriptorSetUniformBuffersDynamic					= 8;
1020 	props->limits.maxDescriptorSetStorageBuffers						= 24;
1021 	props->limits.maxDescriptorSetStorageBuffersDynamic					= 4;
1022 	props->limits.maxDescriptorSetSampledImages							= 96;
1023 	props->limits.maxDescriptorSetStorageImages							= 24;
1024 	props->limits.maxDescriptorSetInputAttachments						= 4;
1025 	props->limits.maxVertexInputAttributes								= 16;
1026 	props->limits.maxVertexInputBindings								= 16;
1027 	props->limits.maxVertexInputAttributeOffset							= 2047;
1028 	props->limits.maxVertexInputBindingStride							= 2048;
1029 	props->limits.maxVertexOutputComponents								= 64;
1030 	props->limits.maxTessellationGenerationLevel						= 64;
1031 	props->limits.maxTessellationPatchSize								= 32;
1032 	props->limits.maxTessellationControlPerVertexInputComponents		= 64;
1033 	props->limits.maxTessellationControlPerVertexOutputComponents		= 64;
1034 	props->limits.maxTessellationControlPerPatchOutputComponents		= 120;
1035 	props->limits.maxTessellationControlTotalOutputComponents			= 2048;
1036 	props->limits.maxTessellationEvaluationInputComponents				= 64;
1037 	props->limits.maxTessellationEvaluationOutputComponents				= 64;
1038 	props->limits.maxGeometryShaderInvocations							= 32;
1039 	props->limits.maxGeometryInputComponents							= 64;
1040 	props->limits.maxGeometryOutputComponents							= 64;
1041 	props->limits.maxGeometryOutputVertices								= 256;
1042 	props->limits.maxGeometryTotalOutputComponents						= 1024;
1043 	props->limits.maxFragmentInputComponents							= 64;
1044 	props->limits.maxFragmentOutputAttachments							= 4;
1045 	props->limits.maxFragmentDualSrcAttachments							= 1;
1046 	props->limits.maxFragmentCombinedOutputResources					= 4;
1047 	props->limits.maxComputeSharedMemorySize							= 16384;
1048 	props->limits.maxComputeWorkGroupCount[0]							= 65535;
1049 	props->limits.maxComputeWorkGroupCount[1]							= 65535;
1050 	props->limits.maxComputeWorkGroupCount[2]							= 65535;
1051 	props->limits.maxComputeWorkGroupInvocations						= 128;
1052 	props->limits.maxComputeWorkGroupSize[0]							= 128;
1053 	props->limits.maxComputeWorkGroupSize[1]							= 128;
1054 	props->limits.maxComputeWorkGroupSize[2]							= 128;
1055 	props->limits.subPixelPrecisionBits									= 4;
1056 	props->limits.subTexelPrecisionBits									= 4;
1057 	props->limits.mipmapPrecisionBits									= 4;
1058 	props->limits.maxDrawIndexedIndexValue								= 0xffffffffu;
1059 	props->limits.maxDrawIndirectCount									= (1u<<16) - 1u;
1060 	props->limits.maxSamplerLodBias										= 2.0f;
1061 	props->limits.maxSamplerAnisotropy									= 16.0f;
1062 	props->limits.maxViewports											= 16;
1063 	props->limits.maxViewportDimensions[0]								= 4096;
1064 	props->limits.maxViewportDimensions[1]								= 4096;
1065 	props->limits.viewportBoundsRange[0]								= -8192.f;
1066 	props->limits.viewportBoundsRange[1]								= 8191.f;
1067 	props->limits.viewportSubPixelBits									= 0;
1068 	props->limits.minMemoryMapAlignment									= 64;
1069 	props->limits.minTexelBufferOffsetAlignment							= 256;
1070 	props->limits.minUniformBufferOffsetAlignment						= 256;
1071 	props->limits.minStorageBufferOffsetAlignment						= 256;
1072 	props->limits.minTexelOffset										= -8;
1073 	props->limits.maxTexelOffset										= 7;
1074 	props->limits.minTexelGatherOffset									= -8;
1075 	props->limits.maxTexelGatherOffset									= 7;
1076 	props->limits.minInterpolationOffset								= -0.5f;
1077 	props->limits.maxInterpolationOffset								= 0.5f; // -1ulp
1078 	props->limits.subPixelInterpolationOffsetBits						= 4;
1079 	props->limits.maxFramebufferWidth									= 4096;
1080 	props->limits.maxFramebufferHeight									= 4096;
1081 	props->limits.maxFramebufferLayers									= 256;
1082 	props->limits.framebufferColorSampleCounts							= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1083 	props->limits.framebufferDepthSampleCounts							= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1084 	props->limits.framebufferStencilSampleCounts						= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1085 	props->limits.framebufferNoAttachmentsSampleCounts					= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1086 	props->limits.maxColorAttachments									= 4;
1087 	props->limits.sampledImageColorSampleCounts							= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1088 	props->limits.sampledImageIntegerSampleCounts						= VK_SAMPLE_COUNT_1_BIT;
1089 	props->limits.sampledImageDepthSampleCounts							= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1090 	props->limits.sampledImageStencilSampleCounts						= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1091 	props->limits.storageImageSampleCounts								= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1092 	props->limits.maxSampleMaskWords									= 1;
1093 	props->limits.timestampComputeAndGraphics							= VK_TRUE;
1094 	props->limits.timestampPeriod										= 1.0f;
1095 	props->limits.maxClipDistances										= 8;
1096 	props->limits.maxCullDistances										= 8;
1097 	props->limits.maxCombinedClipAndCullDistances						= 8;
1098 	props->limits.discreteQueuePriorities								= 2;
1099 	props->limits.pointSizeRange[0]										= 1.0f;
1100 	props->limits.pointSizeRange[1]										= 64.0f; // -1ulp
1101 	props->limits.lineWidthRange[0]										= 1.0f;
1102 	props->limits.lineWidthRange[1]										= 8.0f; // -1ulp
1103 	props->limits.pointSizeGranularity									= 1.0f;
1104 	props->limits.lineWidthGranularity									= 1.0f;
1105 	props->limits.strictLines											= 0;
1106 	props->limits.standardSampleLocations								= VK_TRUE;
1107 	props->limits.optimalBufferCopyOffsetAlignment						= 256;
1108 	props->limits.optimalBufferCopyRowPitchAlignment					= 256;
1109 	props->limits.nonCoherentAtomSize									= 128;
1110 }
1111 
getPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice,deUint32 * count,VkQueueFamilyProperties * props)1112 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceQueueFamilyProperties (VkPhysicalDevice, deUint32* count, VkQueueFamilyProperties* props)
1113 {
1114 	if (props && *count >= 1u)
1115 	{
1116 		deMemset(props, 0, sizeof(VkQueueFamilyProperties));
1117 
1118 		props->queueCount			= 4u;
1119 		props->queueFlags			= VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT;
1120 		props->timestampValidBits	= 64;
1121 	}
1122 
1123 	*count = 1u;
1124 }
1125 
getPhysicalDeviceMemoryProperties(VkPhysicalDevice,VkPhysicalDeviceMemoryProperties * props)1126 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceMemoryProperties (VkPhysicalDevice, VkPhysicalDeviceMemoryProperties* props)
1127 {
1128 	deMemset(props, 0, sizeof(VkPhysicalDeviceMemoryProperties));
1129 
1130 	props->memoryTypeCount				= 1u;
1131 	props->memoryTypes[0].heapIndex		= 0u;
1132 	props->memoryTypes[0].propertyFlags	= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
1133 										| VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
1134 										| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
1135 
1136 	props->memoryHeapCount				= 1u;
1137 	props->memoryHeaps[0].size			= 1ull << 31;
1138 	props->memoryHeaps[0].flags			= 0u;
1139 }
1140 
getPhysicalDeviceFormatProperties(VkPhysicalDevice,VkFormat format,VkFormatProperties * pFormatProperties)1141 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceFormatProperties (VkPhysicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
1142 {
1143 	const VkFormatFeatureFlags	allFeatures	= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
1144 											| VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
1145 											| VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
1146 											| VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
1147 											| VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
1148 											| VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
1149 											| VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
1150 											| VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
1151 											| VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
1152 											| VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
1153 											| VK_FORMAT_FEATURE_BLIT_SRC_BIT
1154 											| VK_FORMAT_FEATURE_BLIT_DST_BIT
1155 											| VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
1156 											| VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT
1157 											| VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT
1158 											| VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT
1159 											| VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT
1160 											| VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT
1161 											| VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
1162 
1163 	pFormatProperties->linearTilingFeatures		= allFeatures;
1164 	pFormatProperties->optimalTilingFeatures	= allFeatures;
1165 	pFormatProperties->bufferFeatures			= allFeatures;
1166 
1167 	if (isYCbCrFormat(format) && getPlaneCount(format) > 1)
1168 		pFormatProperties->optimalTilingFeatures |= VK_FORMAT_FEATURE_DISJOINT_BIT;
1169 }
1170 
getPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkImageFormatProperties * pImageFormatProperties)1171 VKAPI_ATTR VkResult VKAPI_CALL getPhysicalDeviceImageFormatProperties (VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
1172 {
1173 	DE_UNREF(physicalDevice);
1174 	DE_UNREF(format);
1175 	DE_UNREF(type);
1176 	DE_UNREF(tiling);
1177 	DE_UNREF(usage);
1178 	DE_UNREF(flags);
1179 
1180 	pImageFormatProperties->maxArrayLayers		= 8;
1181 	pImageFormatProperties->maxExtent.width		= 4096;
1182 	pImageFormatProperties->maxExtent.height	= 4096;
1183 	pImageFormatProperties->maxExtent.depth		= 4096;
1184 	pImageFormatProperties->maxMipLevels		= deLog2Ceil32(4096) + 1;
1185 	pImageFormatProperties->maxResourceSize		= 64u * 1024u * 1024u;
1186 	pImageFormatProperties->sampleCounts		= VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT;
1187 
1188 	return VK_SUCCESS;
1189 }
1190 
getDeviceQueue(VkDevice device,deUint32 queueFamilyIndex,deUint32 queueIndex,VkQueue * pQueue)1191 VKAPI_ATTR void VKAPI_CALL getDeviceQueue (VkDevice device, deUint32 queueFamilyIndex, deUint32 queueIndex, VkQueue* pQueue)
1192 {
1193 	DE_UNREF(device);
1194 	DE_UNREF(queueFamilyIndex);
1195 
1196 	if (pQueue)
1197 		*pQueue = reinterpret_cast<VkQueue>((deUint64)queueIndex + 1);
1198 }
1199 
getBufferMemoryRequirements(VkDevice,VkBuffer bufferHandle,VkMemoryRequirements * requirements)1200 VKAPI_ATTR void VKAPI_CALL getBufferMemoryRequirements (VkDevice, VkBuffer bufferHandle, VkMemoryRequirements* requirements)
1201 {
1202 	const Buffer*	buffer	= reinterpret_cast<const Buffer*>(bufferHandle.getInternal());
1203 
1204 	requirements->memoryTypeBits	= 1u;
1205 	requirements->size				= buffer->getSize();
1206 	requirements->alignment			= (VkDeviceSize)1u;
1207 }
1208 
getPackedImageDataSize(VkFormat format,VkExtent3D extent,VkSampleCountFlagBits samples)1209 VkDeviceSize getPackedImageDataSize (VkFormat format, VkExtent3D extent, VkSampleCountFlagBits samples)
1210 {
1211 	return (VkDeviceSize)getPixelSize(mapVkFormat(format))
1212 			* (VkDeviceSize)extent.width
1213 			* (VkDeviceSize)extent.height
1214 			* (VkDeviceSize)extent.depth
1215 			* (VkDeviceSize)samples;
1216 }
1217 
getCompressedImageDataSize(VkFormat format,VkExtent3D extent)1218 VkDeviceSize getCompressedImageDataSize (VkFormat format, VkExtent3D extent)
1219 {
1220 	try
1221 	{
1222 		const tcu::CompressedTexFormat	tcuFormat		= mapVkCompressedFormat(format);
1223 		const size_t					blockSize		= tcu::getBlockSize(tcuFormat);
1224 		const tcu::IVec3				blockPixelSize	= tcu::getBlockPixelSize(tcuFormat);
1225 		const int						numBlocksX		= deDivRoundUp32((int)extent.width, blockPixelSize.x());
1226 		const int						numBlocksY		= deDivRoundUp32((int)extent.height, blockPixelSize.y());
1227 		const int						numBlocksZ		= deDivRoundUp32((int)extent.depth, blockPixelSize.z());
1228 
1229 		return blockSize*numBlocksX*numBlocksY*numBlocksZ;
1230 	}
1231 	catch (...)
1232 	{
1233 		return 0; // Unsupported compressed format
1234 	}
1235 }
1236 
getYCbCrImageDataSize(VkFormat format,VkExtent3D extent)1237 VkDeviceSize getYCbCrImageDataSize (VkFormat format, VkExtent3D extent)
1238 {
1239 	const PlanarFormatDescription	desc		= getPlanarFormatDescription(format);
1240 	VkDeviceSize					totalSize	= 0;
1241 
1242 	DE_ASSERT(extent.depth == 1);
1243 
1244 	for (deUint32 planeNdx = 0; planeNdx < desc.numPlanes; ++planeNdx)
1245 	{
1246 		const deUint32	elementSize	= desc.planes[planeNdx].elementSizeBytes;
1247 
1248 		totalSize = (VkDeviceSize)deAlign64((deInt64)totalSize, elementSize);
1249 		totalSize += getPlaneSizeInBytes(desc, extent, planeNdx, 0, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
1250 	}
1251 
1252 	return totalSize;
1253 }
1254 
getImageMemoryRequirements(VkDevice,VkImage imageHandle,VkMemoryRequirements * requirements)1255 VKAPI_ATTR void VKAPI_CALL getImageMemoryRequirements (VkDevice, VkImage imageHandle, VkMemoryRequirements* requirements)
1256 {
1257 	const Image*	image	= reinterpret_cast<const Image*>(imageHandle.getInternal());
1258 
1259 	requirements->memoryTypeBits	= 1u;
1260 	requirements->alignment			= 16u;
1261 
1262 	if (isCompressedFormat(image->getFormat()))
1263 		requirements->size = getCompressedImageDataSize(image->getFormat(), image->getExtent());
1264 	else if (isYCbCrFormat(image->getFormat()))
1265 		requirements->size = getYCbCrImageDataSize(image->getFormat(), image->getExtent());
1266 	else
1267 		requirements->size = getPackedImageDataSize(image->getFormat(), image->getExtent(), image->getSamples());
1268 }
1269 
allocateMemory(VkDevice device,const VkMemoryAllocateInfo * pAllocateInfo,const VkAllocationCallbacks * pAllocator,VkDeviceMemory * pMemory)1270 VKAPI_ATTR VkResult VKAPI_CALL allocateMemory (VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory)
1271 {
1272 	const VkExportMemoryAllocateInfo* const					exportInfo	= findStructure<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext);
1273 	const VkImportAndroidHardwareBufferInfoANDROID* const	importInfo	= findStructure<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext);
1274 
1275 	if ((exportInfo && (exportInfo->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) != 0)
1276 		|| (importInfo && importInfo->buffer.internal))
1277 	{
1278 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
1279 		VK_NULL_RETURN((*pMemory = allocateNonDispHandle<ExternalDeviceMemoryAndroid, DeviceMemory, VkDeviceMemory>(device, pAllocateInfo, pAllocator)));
1280 #else
1281 		return VK_ERROR_INVALID_EXTERNAL_HANDLE;
1282 #endif
1283 	}
1284 	else
1285 	{
1286 		VK_NULL_RETURN((*pMemory = allocateNonDispHandle<PrivateDeviceMemory, DeviceMemory, VkDeviceMemory>(device, pAllocateInfo, pAllocator)));
1287 	}
1288 }
1289 
mapMemory(VkDevice,VkDeviceMemory memHandle,VkDeviceSize offset,VkDeviceSize size,VkMemoryMapFlags flags,void ** ppData)1290 VKAPI_ATTR VkResult VKAPI_CALL mapMemory (VkDevice, VkDeviceMemory memHandle, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData)
1291 {
1292 	DeviceMemory* const	memory	= reinterpret_cast<DeviceMemory*>(memHandle.getInternal());
1293 
1294 	DE_UNREF(size);
1295 	DE_UNREF(flags);
1296 
1297 	*ppData = (deUint8*)memory->map() + offset;
1298 
1299 	return VK_SUCCESS;
1300 }
1301 
unmapMemory(VkDevice device,VkDeviceMemory memHandle)1302 VKAPI_ATTR void VKAPI_CALL unmapMemory (VkDevice device, VkDeviceMemory memHandle)
1303 {
1304 	DeviceMemory* const	memory	= reinterpret_cast<DeviceMemory*>(memHandle.getInternal());
1305 
1306 	DE_UNREF(device);
1307 
1308 	memory->unmap();
1309 }
1310 
getMemoryAndroidHardwareBufferANDROID(VkDevice device,const VkMemoryGetAndroidHardwareBufferInfoANDROID * pInfo,pt::AndroidHardwareBufferPtr * pBuffer)1311 VKAPI_ATTR VkResult VKAPI_CALL getMemoryAndroidHardwareBufferANDROID (VkDevice device, const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, pt::AndroidHardwareBufferPtr* pBuffer)
1312 {
1313 	DE_UNREF(device);
1314 
1315 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
1316 	DeviceMemory* const					memory			= reinterpret_cast<ExternalDeviceMemoryAndroid*>(pInfo->memory.getInternal());
1317 	ExternalDeviceMemoryAndroid* const	androidMemory	= static_cast<ExternalDeviceMemoryAndroid*>(memory);
1318 
1319 	AHardwareBuffer* hwbuffer = androidMemory->getHwBuffer();
1320 	AHardwareBuffer_acquire(hwbuffer);
1321 	pBuffer->internal = hwbuffer;
1322 #else
1323 	DE_UNREF(pInfo);
1324 	DE_UNREF(pBuffer);
1325 #endif
1326 
1327 	return VK_SUCCESS;
1328 }
1329 
allocateDescriptorSets(VkDevice,const VkDescriptorSetAllocateInfo * pAllocateInfo,VkDescriptorSet * pDescriptorSets)1330 VKAPI_ATTR VkResult VKAPI_CALL allocateDescriptorSets (VkDevice, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
1331 {
1332 	DescriptorPool* const	poolImpl	= reinterpret_cast<DescriptorPool*>((deUintptr)pAllocateInfo->descriptorPool.getInternal());
1333 
1334 	for (deUint32 ndx = 0; ndx < pAllocateInfo->descriptorSetCount; ++ndx)
1335 	{
1336 		try
1337 		{
1338 			pDescriptorSets[ndx] = poolImpl->allocate(pAllocateInfo->pSetLayouts[ndx]);
1339 		}
1340 		catch (const std::bad_alloc&)
1341 		{
1342 			for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
1343 				delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
1344 
1345 			return VK_ERROR_OUT_OF_HOST_MEMORY;
1346 		}
1347 		catch (VkResult res)
1348 		{
1349 			for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
1350 				delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
1351 
1352 			return res;
1353 		}
1354 	}
1355 
1356 	return VK_SUCCESS;
1357 }
1358 
freeDescriptorSets(VkDevice,VkDescriptorPool descriptorPool,deUint32 count,const VkDescriptorSet * pDescriptorSets)1359 VKAPI_ATTR void VKAPI_CALL freeDescriptorSets (VkDevice, VkDescriptorPool descriptorPool, deUint32 count, const VkDescriptorSet* pDescriptorSets)
1360 {
1361 	DescriptorPool* const	poolImpl	= reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
1362 
1363 	for (deUint32 ndx = 0; ndx < count; ++ndx)
1364 		poolImpl->free(pDescriptorSets[ndx]);
1365 }
1366 
resetDescriptorPool(VkDevice,VkDescriptorPool descriptorPool,VkDescriptorPoolResetFlags)1367 VKAPI_ATTR VkResult VKAPI_CALL resetDescriptorPool (VkDevice, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags)
1368 {
1369 	DescriptorPool* const	poolImpl	= reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
1370 
1371 	poolImpl->reset();
1372 
1373 	return VK_SUCCESS;
1374 }
1375 
allocateCommandBuffers(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers)1376 VKAPI_ATTR VkResult VKAPI_CALL allocateCommandBuffers (VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
1377 {
1378 	DE_UNREF(device);
1379 
1380 	if (pAllocateInfo && pCommandBuffers)
1381 	{
1382 		CommandPool* const	poolImpl	= reinterpret_cast<CommandPool*>((deUintptr)pAllocateInfo->commandPool.getInternal());
1383 
1384 		for (deUint32 ndx = 0; ndx < pAllocateInfo->commandBufferCount; ++ndx)
1385 			pCommandBuffers[ndx] = poolImpl->allocate(pAllocateInfo->level);
1386 	}
1387 
1388 	return VK_SUCCESS;
1389 }
1390 
freeCommandBuffers(VkDevice device,VkCommandPool commandPool,deUint32 commandBufferCount,const VkCommandBuffer * pCommandBuffers)1391 VKAPI_ATTR void VKAPI_CALL freeCommandBuffers (VkDevice device, VkCommandPool commandPool, deUint32 commandBufferCount, const VkCommandBuffer* pCommandBuffers)
1392 {
1393 	CommandPool* const	poolImpl	= reinterpret_cast<CommandPool*>((deUintptr)commandPool.getInternal());
1394 
1395 	DE_UNREF(device);
1396 
1397 	for (deUint32 ndx = 0; ndx < commandBufferCount; ++ndx)
1398 		poolImpl->free(pCommandBuffers[ndx]);
1399 }
1400 
1401 
createDisplayModeKHR(VkPhysicalDevice,VkDisplayKHR display,const VkDisplayModeCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDisplayModeKHR * pMode)1402 VKAPI_ATTR VkResult VKAPI_CALL createDisplayModeKHR (VkPhysicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode)
1403 {
1404 	DE_UNREF(pAllocator);
1405 	VK_NULL_RETURN((*pMode = allocateNonDispHandle<DisplayModeKHR, VkDisplayModeKHR>(display, pCreateInfo, pAllocator)));
1406 }
1407 
createSharedSwapchainsKHR(VkDevice device,deUint32 swapchainCount,const VkSwapchainCreateInfoKHR * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchains)1408 VKAPI_ATTR VkResult VKAPI_CALL createSharedSwapchainsKHR (VkDevice device, deUint32 swapchainCount, const VkSwapchainCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains)
1409 {
1410 	for (deUint32 ndx = 0; ndx < swapchainCount; ++ndx)
1411 	{
1412 		pSwapchains[ndx] = allocateNonDispHandle<SwapchainKHR, VkSwapchainKHR>(device, pCreateInfos+ndx, pAllocator);
1413 	}
1414 
1415 	return VK_SUCCESS;
1416 }
1417 
getPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceExternalBufferInfo * pExternalBufferInfo,VkExternalBufferProperties * pExternalBufferProperties)1418 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceExternalBufferPropertiesKHR (VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties)
1419 {
1420 	DE_UNREF(physicalDevice);
1421 	DE_UNREF(pExternalBufferInfo);
1422 
1423 	pExternalBufferProperties->externalMemoryProperties.externalMemoryFeatures = 0;
1424 	pExternalBufferProperties->externalMemoryProperties.exportFromImportedHandleTypes = 0;
1425 	pExternalBufferProperties->externalMemoryProperties.compatibleHandleTypes = 0;
1426 
1427 	if (pExternalBufferInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
1428 	{
1429 		pExternalBufferProperties->externalMemoryProperties.externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1430 		pExternalBufferProperties->externalMemoryProperties.exportFromImportedHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1431 		pExternalBufferProperties->externalMemoryProperties.compatibleHandleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1432 	}
1433 }
1434 
getPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkImageFormatProperties2 * pImageFormatProperties)1435 VKAPI_ATTR VkResult VKAPI_CALL getPhysicalDeviceImageFormatProperties2KHR (VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties)
1436 {
1437 	const VkPhysicalDeviceExternalImageFormatInfo* const	externalInfo		= findStructure<VkPhysicalDeviceExternalImageFormatInfo>(pImageFormatInfo->pNext);
1438 	VkExternalImageFormatProperties*	const				externalProperties	= findStructure<VkExternalImageFormatProperties>(pImageFormatProperties->pNext);
1439 	VkResult												result;
1440 
1441 	result = getPhysicalDeviceImageFormatProperties(physicalDevice, pImageFormatInfo->format, pImageFormatInfo->type, pImageFormatInfo->tiling, pImageFormatInfo->usage, pImageFormatInfo->flags, &pImageFormatProperties->imageFormatProperties);
1442 	if (result != VK_SUCCESS)
1443 		return result;
1444 
1445 	if (externalInfo && externalInfo->handleType != 0)
1446 	{
1447 		if (externalInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
1448 			return VK_ERROR_FORMAT_NOT_SUPPORTED;
1449 
1450 		if (!(pImageFormatInfo->format == VK_FORMAT_R8G8B8A8_UNORM
1451 			  || pImageFormatInfo->format == VK_FORMAT_R8G8B8_UNORM
1452 			  || pImageFormatInfo->format == VK_FORMAT_R5G6B5_UNORM_PACK16
1453 			  || pImageFormatInfo->format == VK_FORMAT_R16G16B16A16_SFLOAT
1454 			  || pImageFormatInfo->format == VK_FORMAT_A2R10G10B10_UNORM_PACK32))
1455 		{
1456 			return VK_ERROR_FORMAT_NOT_SUPPORTED;
1457 		}
1458 
1459 		if (pImageFormatInfo->type != VK_IMAGE_TYPE_2D)
1460 			return VK_ERROR_FORMAT_NOT_SUPPORTED;
1461 
1462 		if ((pImageFormatInfo->usage & ~(VK_IMAGE_USAGE_TRANSFER_SRC_BIT
1463 										| VK_IMAGE_USAGE_TRANSFER_DST_BIT
1464 										| VK_IMAGE_USAGE_SAMPLED_BIT
1465 										| VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT))
1466 			!= 0)
1467 		{
1468 			return VK_ERROR_FORMAT_NOT_SUPPORTED;
1469 		}
1470 
1471 		if ((pImageFormatInfo->flags & ~(VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
1472 										/*| VK_IMAGE_CREATE_PROTECTED_BIT*/
1473 										/*| VK_IMAGE_CREATE_EXTENDED_USAGE_BIT*/))
1474 			!= 0)
1475 		{
1476 			return VK_ERROR_FORMAT_NOT_SUPPORTED;
1477 		}
1478 
1479 		if (externalProperties)
1480 		{
1481 			externalProperties->externalMemoryProperties.externalMemoryFeatures			= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT
1482 																						| VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
1483 																						| VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1484 			externalProperties->externalMemoryProperties.exportFromImportedHandleTypes	= VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1485 			externalProperties->externalMemoryProperties.compatibleHandleTypes			= VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1486 		}
1487 	}
1488 
1489 	return VK_SUCCESS;
1490 }
1491 
1492 // \note getInstanceProcAddr is a little bit special:
1493 // vkNullDriverImpl.inl needs it to define s_platformFunctions but
1494 // getInstanceProcAddr() implementation needs other entry points from
1495 // vkNullDriverImpl.inl.
1496 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName);
1497 
1498 #include "vkNullDriverImpl.inl"
1499 
getInstanceProcAddr(VkInstance instance,const char * pName)1500 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName)
1501 {
1502 	if (instance)
1503 	{
1504 		return reinterpret_cast<Instance*>(instance)->getProcAddr(pName);
1505 	}
1506 	else
1507 	{
1508 		const std::string	name	= pName;
1509 
1510 		if (name == "vkCreateInstance")
1511 			return (PFN_vkVoidFunction)createInstance;
1512 		else if (name == "vkEnumerateInstanceExtensionProperties")
1513 			return (PFN_vkVoidFunction)enumerateInstanceExtensionProperties;
1514 		else if (name == "vkEnumerateInstanceLayerProperties")
1515 			return (PFN_vkVoidFunction)enumerateInstanceLayerProperties;
1516 		else
1517 			return (PFN_vkVoidFunction)DE_NULL;
1518 	}
1519 }
1520 
1521 } // extern "C"
1522 
Instance(const VkInstanceCreateInfo *)1523 Instance::Instance (const VkInstanceCreateInfo*)
1524 	: m_functions(s_instanceFunctions, DE_LENGTH_OF_ARRAY(s_instanceFunctions))
1525 {
1526 }
1527 
Device(VkPhysicalDevice,const VkDeviceCreateInfo *)1528 Device::Device (VkPhysicalDevice, const VkDeviceCreateInfo*)
1529 	: m_functions(s_deviceFunctions, DE_LENGTH_OF_ARRAY(s_deviceFunctions))
1530 {
1531 }
1532 
1533 class NullDriverLibrary : public Library
1534 {
1535 public:
NullDriverLibrary(void)1536 										NullDriverLibrary (void)
1537 											: m_library	(s_platformFunctions, DE_LENGTH_OF_ARRAY(s_platformFunctions))
1538 											, m_driver	(m_library)
1539 										{}
1540 
getPlatformInterface(void) const1541 	const PlatformInterface&			getPlatformInterface	(void) const	{ return m_driver;	}
getFunctionLibrary(void) const1542 	const tcu::FunctionLibrary&			getFunctionLibrary		(void) const	{ return m_library;	}
1543 private:
1544 	const tcu::StaticFunctionLibrary	m_library;
1545 	const PlatformDriver				m_driver;
1546 };
1547 
1548 } // anonymous
1549 
createNullDriver(void)1550 Library* createNullDriver (void)
1551 {
1552 	return new NullDriverLibrary();
1553 }
1554 
1555 } // vk
1556