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