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