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