1 /*-------------------------------------------------------------------------
5 * Copyright (c) 2015 Google Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Null (do-nothing) Vulkan implementation.
22 *//*--------------------------------------------------------------------*/
24 #include "vkNullDriver.hpp"
25 #include "vkPlatform.hpp"
26 #include "vkImageUtil.hpp"
27 #include "vkQueryUtil.hpp"
28 #include "tcuFunctionLibrary.hpp"
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
34 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
35 # include <android/hardware_buffer.h>
52 void* allocateSystemMem (const VkAllocationCallbacks* pAllocator, VkSystemAllocationScope scope)
54 void* ptr = pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(T), sizeof(void*), scope);
56 throw std::bad_alloc();
60 void freeSystemMem (const VkAllocationCallbacks* pAllocator, void* mem)
62 pAllocator->pfnFree(pAllocator->pUserData, mem);
65 template<typename Object, typename Handle, typename Parent, typename CreateInfo>
66 Handle allocateHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
68 Object* obj = DE_NULL;
72 void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
75 obj = new (mem) Object(parent, pCreateInfo);
76 DE_ASSERT(obj == mem);
80 pAllocator->pfnFree(pAllocator->pUserData, mem);
85 obj = new Object(parent, pCreateInfo);
87 return reinterpret_cast<Handle>(obj);
90 template<typename Object, typename Handle, typename CreateInfo>
91 Handle allocateHandle (const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
93 Object* obj = DE_NULL;
97 void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
100 obj = new (mem) Object(pCreateInfo);
101 DE_ASSERT(obj == mem);
105 pAllocator->pfnFree(pAllocator->pUserData, mem);
110 obj = new Object(pCreateInfo);
112 return reinterpret_cast<Handle>(obj);
115 template<typename Object, typename Handle, typename Parent>
116 Handle allocateHandle (Parent parent, const VkAllocationCallbacks* pAllocator)
118 Object* obj = DE_NULL;
122 void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
125 obj = new (mem) Object(parent);
126 DE_ASSERT(obj == mem);
130 pAllocator->pfnFree(pAllocator->pUserData, mem);
135 obj = new Object(parent);
137 return reinterpret_cast<Handle>(obj);
140 template<typename Object, typename Handle>
141 void freeHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
143 Object* obj = reinterpret_cast<Object*>(handle);
148 freeSystemMem(pAllocator, reinterpret_cast<void*>(obj));
154 template<typename Object, typename BaseObject, typename Handle, typename Parent, typename CreateInfo>
155 Handle allocateNonDispHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
157 Object* const obj = allocateHandle<Object, Object*>(parent, pCreateInfo, pAllocator);
158 return Handle((deUint64)(deUintptr)static_cast<BaseObject*>(obj));
161 template<typename Object, typename Handle, typename Parent, typename CreateInfo>
162 Handle allocateNonDispHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
164 return allocateNonDispHandle<Object, Object, Handle, Parent, CreateInfo>(parent, pCreateInfo, pAllocator);
167 template<typename Object, typename Handle, typename Parent>
168 Handle allocateNonDispHandle (Parent parent, const VkAllocationCallbacks* pAllocator)
170 Object* const obj = allocateHandle<Object, Object*>(parent, pAllocator);
171 return Handle((deUint64)(deUintptr)obj);
174 template<typename Object, typename Handle>
175 void freeNonDispHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
177 freeHandle<Object>(reinterpret_cast<Object*>((deUintptr)handle.getInternal()), pAllocator);
180 // Object definitions
182 #define VK_NULL_RETURN(STMT) \
187 } catch (const std::bad_alloc&) { \
188 return VK_ERROR_OUT_OF_HOST_MEMORY; \
189 } catch (VkResult res) { \
192 } while (deGetFalse())
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)
197 #define VK_NULL_DEFINE_DEVICE_OBJ(NAME) \
200 NAME (VkDevice, const Vk##NAME##CreateInfo*) {} \
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);
221 Instance (const VkInstanceCreateInfo* instanceInfo);
224 PFN_vkVoidFunction getProcAddr (const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
227 const tcu::StaticFunctionLibrary m_functions;
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) {}
255 DisplayModeKHR (VkDisplayKHR, const VkDisplayModeCreateInfoKHR*) {}
256 ~DisplayModeKHR (void) {}
259 #ifndef CTS_USES_VULKANSC
260 class DebugReportCallbackEXT
263 DebugReportCallbackEXT (VkInstance, const VkDebugReportCallbackCreateInfoEXT*) {}
264 ~DebugReportCallbackEXT (void) {}
270 CuModuleNVX (VkDevice, const VkCuModuleCreateInfoNVX*) {}
271 ~CuModuleNVX(void) {}
277 CuFunctionNVX(VkDevice, const VkCuFunctionCreateInfoNVX*) {}
278 ~CuFunctionNVX(void) {}
281 #endif // CTS_USES_VULKANSC
286 Device (VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* deviceInfo);
289 PFN_vkVoidFunction getProcAddr (const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
292 const tcu::StaticFunctionLibrary m_functions;
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
309 RenderPass (VkDevice, const VkRenderPassCreateInfo*) {}
310 RenderPass (VkDevice, const VkRenderPassCreateInfo2*) {}
316 SwapchainKHR (VkDevice, const VkSwapchainCreateInfoKHR*) {}
317 ~SwapchainKHR (void) {}
320 class SamplerYcbcrConversion
323 SamplerYcbcrConversion (VkDevice, const VkSamplerYcbcrConversionCreateInfo*) {}
329 Buffer (VkDevice, const VkBufferCreateInfo* pCreateInfo)
330 : m_size (pCreateInfo->size)
334 VkDeviceSize getSize (void) const { return m_size; }
337 const VkDeviceSize m_size;
340 VkExternalMemoryHandleTypeFlags getExternalTypesHandle (const VkImageCreateInfo* pCreateInfo)
342 const VkExternalMemoryImageCreateInfo* const externalInfo = findStructure<VkExternalMemoryImageCreateInfo> (pCreateInfo->pNext);
344 return externalInfo ? externalInfo->handleTypes : 0u;
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))
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; }
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;
382 void* allocateHeap (const VkMemoryAllocateInfo* pAllocInfo)
384 // \todo [2015-12-03 pyry] Alignment requirements?
385 // \todo [2015-12-03 pyry] Empty allocations okay?
386 if (pAllocInfo->allocationSize > 0)
388 void* const heapPtr = deMalloc((size_t)pAllocInfo->allocationSize);
390 throw std::bad_alloc();
397 void freeHeap (void* ptr)
405 virtual ~DeviceMemory (void) {}
406 virtual void* map (void) = 0;
407 virtual void unmap (void) = 0;
410 class PrivateDeviceMemory : public DeviceMemory
413 PrivateDeviceMemory (VkDevice, const VkMemoryAllocateInfo* pAllocInfo)
414 : m_memory(allocateHeap(pAllocInfo))
416 // \todo [2016-08-03 pyry] In some cases leaving data unintialized would help valgrind analysis,
417 // but currently it mostly hinders it.
419 deMemset(m_memory, 0xcd, (size_t)pAllocInfo->allocationSize);
421 virtual ~PrivateDeviceMemory (void)
426 virtual void* map (void) /*override*/ { return m_memory; }
427 virtual void unmap (void) /*override*/ {}
430 void* const m_memory;
433 #ifndef CTS_USES_VULKANSC
435 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
436 AHardwareBuffer* findOrCreateHwBuffer (const VkMemoryAllocateInfo* pAllocInfo)
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;
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));
448 if (importInfo && importInfo->buffer.internal)
450 hwbuffer = (AHardwareBuffer*)importInfo->buffer.internal;
451 AHardwareBuffer_acquire(hwbuffer);
453 else if (exportInfo && (exportInfo->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) != 0)
455 AHardwareBuffer_Desc hwbufferDesc;
456 deMemset(&hwbufferDesc, 0, sizeof(hwbufferDesc));
460 hwbufferDesc.width = image->getExtent().width;
461 hwbufferDesc.height = image->getExtent().height;
462 hwbufferDesc.layers = image->getArrayLayers();
463 switch (image->getFormat())
465 case VK_FORMAT_R8G8B8A8_UNORM:
466 hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
468 case VK_FORMAT_R8G8B8_UNORM:
469 hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM;
471 case VK_FORMAT_R5G6B5_UNORM_PACK16:
472 hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
474 case VK_FORMAT_R16G16B16A16_SFLOAT:
475 hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
477 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
478 hwbufferDesc.format = AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
481 DE_FATAL("Unsupported image format for Android hardware buffer export");
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;
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;
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;
505 AHardwareBuffer_allocate(&hwbufferDesc, &hwbuffer);
511 class ExternalDeviceMemoryAndroid : public DeviceMemory
514 ExternalDeviceMemoryAndroid (VkDevice, const VkMemoryAllocateInfo* pAllocInfo)
515 : m_hwbuffer(findOrCreateHwBuffer(pAllocInfo))
517 virtual ~ExternalDeviceMemoryAndroid (void)
520 AHardwareBuffer_release(m_hwbuffer);
523 virtual void* map (void) /*override*/
526 AHardwareBuffer_lock(m_hwbuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1, NULL, &p);
530 virtual void unmap (void) /*override*/ { AHardwareBuffer_unlock(m_hwbuffer, NULL); }
532 AHardwareBuffer* getHwBuffer (void) { return m_hwbuffer; }
535 AHardwareBuffer* const m_hwbuffer;
537 #endif // defined(USE_ANDROID_O_HARDWARE_BUFFER)
539 class IndirectCommandsLayoutNV
542 IndirectCommandsLayoutNV (VkDevice, const VkIndirectCommandsLayoutCreateInfoNV*)
546 class AccelerationStructureNV
549 AccelerationStructureNV (VkDevice, const VkAccelerationStructureCreateInfoNV*)
553 class AccelerationStructureKHR
556 AccelerationStructureKHR (VkDevice, const VkAccelerationStructureCreateInfoKHR*)
560 #endif // CTS_USES_VULKANSC
562 class DebugUtilsMessengerEXT
565 DebugUtilsMessengerEXT(VkInstance, const VkDebugUtilsMessengerCreateInfoEXT*)
569 class DeferredOperationKHR
572 DeferredOperationKHR (VkDevice)
576 #ifndef CTS_USES_VULKANSC
578 class VideoSessionKHR
581 VideoSessionKHR (VkDevice, const VkVideoSessionCreateInfoKHR*)
585 class VideoSessionParametersKHR
588 VideoSessionParametersKHR (VkDevice, const VkVideoSessionParametersCreateInfoKHR*)
592 class ValidationCacheEXT
595 ValidationCacheEXT (VkDevice, const VkValidationCacheCreateInfoEXT*)
599 #endif // CTS_USES_VULKANSC
604 CommandBuffer (VkDevice, VkCommandPool, VkCommandBufferLevel)
608 #ifndef CTS_USES_VULKANSC
610 class DescriptorUpdateTemplate
613 DescriptorUpdateTemplate (VkDevice, const VkDescriptorUpdateTemplateCreateInfo*)
617 class PrivateDataSlot
620 PrivateDataSlot (VkDevice, const VkPrivateDataSlotCreateInfo*)
624 class BufferCollectionFUCHSIA
627 BufferCollectionFUCHSIA (VkDevice, const VkBufferCollectionCreateInfoFUCHSIA*)
631 #endif // CTS_USES_VULKANSC
636 CommandPool (VkDevice device, const VkCommandPoolCreateInfo*)
639 #ifndef CTS_USES_VULKANSC
641 #endif // CTS_USES_VULKANSC
643 VkCommandBuffer allocate (VkCommandBufferLevel level);
644 void free (VkCommandBuffer buffer);
647 const VkDevice m_device;
649 vector<CommandBuffer*> m_buffers;
652 #ifndef CTS_USES_VULKANSC
654 CommandPool::~CommandPool (void)
656 for (size_t ndx = 0; ndx < m_buffers.size(); ++ndx)
657 delete m_buffers[ndx];
660 #endif // CTS_USES_VULKANSC
662 VkCommandBuffer CommandPool::allocate (VkCommandBufferLevel level)
664 CommandBuffer* const impl = new CommandBuffer(m_device, VkCommandPool(reinterpret_cast<deUintptr>(this)), level);
668 m_buffers.push_back(impl);
676 return reinterpret_cast<VkCommandBuffer>(impl);
679 void CommandPool::free (VkCommandBuffer buffer)
681 CommandBuffer* const impl = reinterpret_cast<CommandBuffer*>(buffer);
683 for (size_t ndx = 0; ndx < m_buffers.size(); ++ndx)
685 if (m_buffers[ndx] == impl)
687 std::swap(m_buffers[ndx], m_buffers.back());
688 m_buffers.pop_back();
694 DE_FATAL("VkCommandBuffer not owned by VkCommandPool");
700 DescriptorSet (VkDevice, VkDescriptorPool, VkDescriptorSetLayout) {}
706 DescriptorPool (VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo)
708 , m_flags (pCreateInfo->flags)
710 ~DescriptorPool (void)
715 VkDescriptorSet allocate (VkDescriptorSetLayout setLayout);
716 void free (VkDescriptorSet set);
721 const VkDevice m_device;
722 const VkDescriptorPoolCreateFlags m_flags;
724 vector<DescriptorSet*> m_managedSets;
727 VkDescriptorSet DescriptorPool::allocate (VkDescriptorSetLayout setLayout)
729 DescriptorSet* const impl = new DescriptorSet(m_device, VkDescriptorPool(reinterpret_cast<deUintptr>(this)), setLayout);
733 m_managedSets.push_back(impl);
741 return VkDescriptorSet(reinterpret_cast<deUintptr>(impl));
744 void DescriptorPool::free (VkDescriptorSet set)
746 DescriptorSet* const impl = reinterpret_cast<DescriptorSet*>((deUintptr)set.getInternal());
748 DE_ASSERT(m_flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT);
751 for (size_t ndx = 0; ndx < m_managedSets.size(); ++ndx)
753 if (m_managedSets[ndx] == impl)
755 std::swap(m_managedSets[ndx], m_managedSets.back());
756 m_managedSets.pop_back();
762 DE_FATAL("VkDescriptorSet not owned by VkDescriptorPool");
765 void DescriptorPool::reset (void)
767 for (size_t ndx = 0; ndx < m_managedSets.size(); ++ndx)
768 delete m_managedSets[ndx];
769 m_managedSets.clear();
772 // API implementation
777 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getDeviceProcAddr (VkDevice device, const char* pName)
779 return reinterpret_cast<Device*>(device)->getProcAddr(pName);
782 VKAPI_ATTR VkResult VKAPI_CALL createGraphicsPipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
787 for (allocNdx = 0; allocNdx < count; allocNdx++)
788 pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
792 catch (const std::bad_alloc&)
794 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
795 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
797 return VK_ERROR_OUT_OF_HOST_MEMORY;
801 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
802 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
808 VKAPI_ATTR VkResult VKAPI_CALL createComputePipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
813 for (allocNdx = 0; allocNdx < count; allocNdx++)
814 pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
818 catch (const std::bad_alloc&)
820 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
821 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
823 return VK_ERROR_OUT_OF_HOST_MEMORY;
827 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
828 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
834 #ifndef CTS_USES_VULKANSC
836 VKAPI_ATTR VkResult VKAPI_CALL createRayTracingPipelinesNV (VkDevice device, VkPipelineCache, deUint32 count, const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
841 for (allocNdx = 0; allocNdx < count; allocNdx++)
842 pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
846 catch (const std::bad_alloc&)
848 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
849 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
851 return VK_ERROR_OUT_OF_HOST_MEMORY;
855 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
856 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
862 VKAPI_ATTR VkResult VKAPI_CALL createRayTracingPipelinesKHR (VkDevice device, VkPipelineCache, deUint32 count, const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
867 for (allocNdx = 0; allocNdx < count; allocNdx++)
868 pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
872 catch (const std::bad_alloc&)
874 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
875 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
877 return VK_ERROR_OUT_OF_HOST_MEMORY;
881 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
882 freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
888 #endif // CTS_USES_VULKANSC
890 VKAPI_ATTR VkResult VKAPI_CALL enumeratePhysicalDevices (VkInstance, deUint32* pPhysicalDeviceCount, VkPhysicalDevice* pDevices)
892 if (pDevices && *pPhysicalDeviceCount >= 1u)
893 *pDevices = reinterpret_cast<VkPhysicalDevice>((void*)(deUintptr)1u);
895 *pPhysicalDeviceCount = 1;
900 VkResult enumerateExtensions (deUint32 numExtensions, const VkExtensionProperties* extensions, deUint32* pPropertyCount, VkExtensionProperties* pProperties)
902 const deUint32 dstSize = pPropertyCount ? *pPropertyCount : 0;
905 *pPropertyCount = numExtensions;
909 for (deUint32 ndx = 0; ndx < de::min(numExtensions, dstSize); ++ndx)
910 pProperties[ndx] = extensions[ndx];
912 if (dstSize < numExtensions)
913 return VK_INCOMPLETE;
919 VKAPI_ATTR VkResult VKAPI_CALL enumerateInstanceExtensionProperties (const char* pLayerName, deUint32* pPropertyCount, VkExtensionProperties* pProperties)
921 static const VkExtensionProperties s_extensions[] =
923 { "VK_KHR_get_physical_device_properties2", 1u },
924 { "VK_KHR_external_memory_capabilities", 1u },
928 return enumerateExtensions((deUint32)DE_LENGTH_OF_ARRAY(s_extensions), s_extensions, pPropertyCount, pProperties);
930 return enumerateExtensions(0, DE_NULL, pPropertyCount, pProperties);
933 VKAPI_ATTR VkResult VKAPI_CALL enumerateDeviceExtensionProperties (VkPhysicalDevice physicalDevice, const char* pLayerName, deUint32* pPropertyCount, VkExtensionProperties* pProperties)
935 DE_UNREF(physicalDevice);
937 static const VkExtensionProperties s_extensions[] =
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 },
950 return enumerateExtensions((deUint32)DE_LENGTH_OF_ARRAY(s_extensions), s_extensions, pPropertyCount, pProperties);
952 return enumerateExtensions(0, DE_NULL, pPropertyCount, pProperties);
955 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceFeatures (VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
957 DE_UNREF(physicalDevice);
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;
1017 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceProperties (VkPhysicalDevice, VkPhysicalDeviceProperties* props)
1019 deMemset(props, 0, sizeof(VkPhysicalDeviceProperties));
1021 props->apiVersion = VK_API_VERSION_1_1;
1022 props->driverVersion = 1u;
1023 props->deviceType = VK_PHYSICAL_DEVICE_TYPE_OTHER;
1025 deMemcpy(props->deviceName, "null", 5);
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;
1144 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceQueueFamilyProperties (VkPhysicalDevice, deUint32* count, VkQueueFamilyProperties* props)
1146 if (props && *count >= 1u)
1148 deMemset(props, 0, sizeof(VkQueueFamilyProperties));
1150 props->queueCount = 4u;
1151 props->queueFlags = VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT;
1152 props->timestampValidBits = 64;
1158 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceMemoryProperties (VkPhysicalDevice, VkPhysicalDeviceMemoryProperties* props)
1160 deMemset(props, 0, sizeof(VkPhysicalDeviceMemoryProperties));
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;
1168 props->memoryHeapCount = 1u;
1169 props->memoryHeaps[0].size = 1ull << 31;
1170 props->memoryHeaps[0].flags = 0u;
1173 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceFormatProperties (VkPhysicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
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;
1195 pFormatProperties->linearTilingFeatures = allFeatures;
1196 pFormatProperties->optimalTilingFeatures = allFeatures;
1197 pFormatProperties->bufferFeatures = allFeatures;
1199 if (isYCbCrFormat(format) && getPlaneCount(format) > 1)
1200 pFormatProperties->optimalTilingFeatures |= VK_FORMAT_FEATURE_DISJOINT_BIT;
1203 VKAPI_ATTR VkResult VKAPI_CALL getPhysicalDeviceImageFormatProperties (VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
1205 DE_UNREF(physicalDevice);
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;
1223 VKAPI_ATTR void VKAPI_CALL getDeviceQueue (VkDevice device, deUint32 queueFamilyIndex, deUint32 queueIndex, VkQueue* pQueue)
1226 DE_UNREF(queueFamilyIndex);
1229 *pQueue = reinterpret_cast<VkQueue>((deUint64)queueIndex + 1);
1232 VKAPI_ATTR void VKAPI_CALL getBufferMemoryRequirements (VkDevice, VkBuffer bufferHandle, VkMemoryRequirements* requirements)
1234 const Buffer* buffer = reinterpret_cast<const Buffer*>(bufferHandle.getInternal());
1236 requirements->memoryTypeBits = 1u;
1237 requirements->size = buffer->getSize();
1238 requirements->alignment = (VkDeviceSize)1u;
1241 VkDeviceSize getPackedImageDataSize (VkFormat format, VkExtent3D extent, VkSampleCountFlagBits samples)
1243 return (VkDeviceSize)getPixelSize(mapVkFormat(format))
1244 * (VkDeviceSize)extent.width
1245 * (VkDeviceSize)extent.height
1246 * (VkDeviceSize)extent.depth
1247 * (VkDeviceSize)samples;
1250 VkDeviceSize getCompressedImageDataSize (VkFormat format, VkExtent3D extent)
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());
1261 return blockSize*numBlocksX*numBlocksY*numBlocksZ;
1265 return 0; // Unsupported compressed format
1269 VkDeviceSize getYCbCrImageDataSize (VkFormat format, VkExtent3D extent)
1271 const PlanarFormatDescription desc = getPlanarFormatDescription(format);
1272 VkDeviceSize totalSize = 0;
1274 DE_ASSERT(extent.depth == 1);
1276 for (deUint32 planeNdx = 0; planeNdx < desc.numPlanes; ++planeNdx)
1278 const deUint32 elementSize = desc.planes[planeNdx].elementSizeBytes;
1280 totalSize = (VkDeviceSize)deAlign64((deInt64)totalSize, elementSize);
1281 totalSize += getPlaneSizeInBytes(desc, extent, planeNdx, 0, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
1287 VKAPI_ATTR void VKAPI_CALL getImageMemoryRequirements (VkDevice, VkImage imageHandle, VkMemoryRequirements* requirements)
1289 const Image* image = reinterpret_cast<const Image*>(imageHandle.getInternal());
1291 requirements->memoryTypeBits = 1u;
1292 requirements->alignment = 16u;
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());
1299 requirements->size = getPackedImageDataSize(image->getFormat(), image->getExtent(), image->getSamples());
1302 VKAPI_ATTR VkResult VKAPI_CALL allocateMemory (VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory)
1304 #ifndef CTS_USES_VULKANSC
1305 const VkExportMemoryAllocateInfo* const exportInfo = findStructure<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext);
1306 const VkImportAndroidHardwareBufferInfoANDROID* const importInfo = findStructure<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext);
1308 if ((exportInfo && (exportInfo->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) != 0)
1309 || (importInfo && importInfo->buffer.internal))
1311 #if defined(USE_ANDROID_O_HARDWARE_BUFFER)
1312 VK_NULL_RETURN((*pMemory = allocateNonDispHandle<ExternalDeviceMemoryAndroid, DeviceMemory, VkDeviceMemory>(device, pAllocateInfo, pAllocator)));
1314 return VK_ERROR_INVALID_EXTERNAL_HANDLE;
1319 VK_NULL_RETURN((*pMemory = allocateNonDispHandle<PrivateDeviceMemory, DeviceMemory, VkDeviceMemory>(device, pAllocateInfo, pAllocator)));
1321 #else // CTS_USES_VULKANSC
1322 VK_NULL_RETURN((*pMemory = allocateNonDispHandle<PrivateDeviceMemory, DeviceMemory, VkDeviceMemory>(device, pAllocateInfo, pAllocator)));
1323 #endif // CTS_USES_VULKANSC
1326 VKAPI_ATTR VkResult VKAPI_CALL mapMemory (VkDevice, VkDeviceMemory memHandle, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData)
1328 DeviceMemory* const memory = reinterpret_cast<DeviceMemory*>(memHandle.getInternal());
1333 *ppData = (deUint8*)memory->map() + offset;
1338 VKAPI_ATTR void VKAPI_CALL unmapMemory (VkDevice device, VkDeviceMemory memHandle)
1340 DeviceMemory* const memory = reinterpret_cast<DeviceMemory*>(memHandle.getInternal());
1347 #ifndef CTS_USES_VULKANSC
1349 VKAPI_ATTR VkResult VKAPI_CALL getMemoryAndroidHardwareBufferANDROID (VkDevice device, const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, pt::AndroidHardwareBufferPtr* pBuffer)
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);
1357 AHardwareBuffer* hwbuffer = androidMemory->getHwBuffer();
1358 AHardwareBuffer_acquire(hwbuffer);
1359 pBuffer->internal = hwbuffer;
1368 #endif // CTS_USES_VULKANSC
1370 VKAPI_ATTR VkResult VKAPI_CALL allocateDescriptorSets (VkDevice, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
1372 DescriptorPool* const poolImpl = reinterpret_cast<DescriptorPool*>((deUintptr)pAllocateInfo->descriptorPool.getInternal());
1374 for (deUint32 ndx = 0; ndx < pAllocateInfo->descriptorSetCount; ++ndx)
1378 pDescriptorSets[ndx] = poolImpl->allocate(pAllocateInfo->pSetLayouts[ndx]);
1380 catch (const std::bad_alloc&)
1382 for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
1383 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
1385 return VK_ERROR_OUT_OF_HOST_MEMORY;
1387 catch (VkResult res)
1389 for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
1390 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
1399 VKAPI_ATTR void VKAPI_CALL freeDescriptorSets (VkDevice, VkDescriptorPool descriptorPool, deUint32 count, const VkDescriptorSet* pDescriptorSets)
1401 DescriptorPool* const poolImpl = reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
1403 for (deUint32 ndx = 0; ndx < count; ++ndx)
1404 poolImpl->free(pDescriptorSets[ndx]);
1407 VKAPI_ATTR VkResult VKAPI_CALL resetDescriptorPool (VkDevice, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags)
1409 DescriptorPool* const poolImpl = reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
1416 VKAPI_ATTR VkResult VKAPI_CALL allocateCommandBuffers (VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
1420 if (pAllocateInfo && pCommandBuffers)
1422 CommandPool* const poolImpl = reinterpret_cast<CommandPool*>((deUintptr)pAllocateInfo->commandPool.getInternal());
1424 for (deUint32 ndx = 0; ndx < pAllocateInfo->commandBufferCount; ++ndx)
1425 pCommandBuffers[ndx] = poolImpl->allocate(pAllocateInfo->level);
1431 VKAPI_ATTR void VKAPI_CALL freeCommandBuffers (VkDevice device, VkCommandPool commandPool, deUint32 commandBufferCount, const VkCommandBuffer* pCommandBuffers)
1433 CommandPool* const poolImpl = reinterpret_cast<CommandPool*>((deUintptr)commandPool.getInternal());
1437 for (deUint32 ndx = 0; ndx < commandBufferCount; ++ndx)
1438 poolImpl->free(pCommandBuffers[ndx]);
1442 VKAPI_ATTR VkResult VKAPI_CALL createDisplayModeKHR (VkPhysicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode)
1444 DE_UNREF(pAllocator);
1445 VK_NULL_RETURN((*pMode = allocateNonDispHandle<DisplayModeKHR, VkDisplayModeKHR>(display, pCreateInfo, pAllocator)));
1448 VKAPI_ATTR VkResult VKAPI_CALL createSharedSwapchainsKHR (VkDevice device, deUint32 swapchainCount, const VkSwapchainCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains)
1450 for (deUint32 ndx = 0; ndx < swapchainCount; ++ndx)
1452 pSwapchains[ndx] = allocateNonDispHandle<SwapchainKHR, VkSwapchainKHR>(device, pCreateInfos+ndx, pAllocator);
1458 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceExternalBufferPropertiesKHR (VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties)
1460 DE_UNREF(physicalDevice);
1461 DE_UNREF(pExternalBufferInfo);
1463 pExternalBufferProperties->externalMemoryProperties.externalMemoryFeatures = 0;
1464 pExternalBufferProperties->externalMemoryProperties.exportFromImportedHandleTypes = 0;
1465 pExternalBufferProperties->externalMemoryProperties.compatibleHandleTypes = 0;
1467 #ifndef CTS_USES_VULKANSC
1468 if (pExternalBufferInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
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;
1474 #endif // CTS_USES_VULKANSC
1477 VKAPI_ATTR VkResult VKAPI_CALL getPhysicalDeviceImageFormatProperties2KHR (VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties)
1479 #ifndef CTS_USES_VULKANSC
1480 const VkPhysicalDeviceExternalImageFormatInfo* const externalInfo = findStructure<VkPhysicalDeviceExternalImageFormatInfo>(pImageFormatInfo->pNext);
1481 VkExternalImageFormatProperties* const externalProperties = findStructure<VkExternalImageFormatProperties>(pImageFormatProperties->pNext);
1484 result = getPhysicalDeviceImageFormatProperties(physicalDevice, pImageFormatInfo->format, pImageFormatInfo->type, pImageFormatInfo->tiling, pImageFormatInfo->usage, pImageFormatInfo->flags, &pImageFormatProperties->imageFormatProperties);
1485 if (result != VK_SUCCESS)
1488 if (externalInfo && externalInfo->handleType != 0)
1490 if (externalInfo->handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
1491 return VK_ERROR_FORMAT_NOT_SUPPORTED;
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))
1499 return VK_ERROR_FORMAT_NOT_SUPPORTED;
1502 if (pImageFormatInfo->type != VK_IMAGE_TYPE_2D)
1503 return VK_ERROR_FORMAT_NOT_SUPPORTED;
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))
1511 return VK_ERROR_FORMAT_NOT_SUPPORTED;
1514 if ((pImageFormatInfo->flags & ~(VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
1515 /*| VK_IMAGE_CREATE_PROTECTED_BIT*/
1516 /*| VK_IMAGE_CREATE_EXTENDED_USAGE_BIT*/))
1519 return VK_ERROR_FORMAT_NOT_SUPPORTED;
1522 if (externalProperties)
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;
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
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);
1544 #include "vkNullDriverImpl.inl"
1546 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName)
1550 return reinterpret_cast<Instance*>(instance)->getProcAddr(pName);
1554 const std::string name = pName;
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;
1563 return (PFN_vkVoidFunction)DE_NULL;
1569 Instance::Instance (const VkInstanceCreateInfo*)
1570 : m_functions(s_instanceFunctions, DE_LENGTH_OF_ARRAY(s_instanceFunctions))
1574 Device::Device (VkPhysicalDevice, const VkDeviceCreateInfo*)
1575 : m_functions(s_deviceFunctions, DE_LENGTH_OF_ARRAY(s_deviceFunctions))
1579 class NullDriverLibrary : public Library
1582 NullDriverLibrary (void)
1583 : m_library (s_platformFunctions, DE_LENGTH_OF_ARRAY(s_platformFunctions))
1584 , m_driver (m_library)
1587 const PlatformInterface& getPlatformInterface (void) const { return m_driver; }
1588 const tcu::FunctionLibrary& getFunctionLibrary (void) const { return m_library; }
1590 const tcu::StaticFunctionLibrary m_library;
1591 const PlatformDriver m_driver;
1596 Library* createNullDriver (void)
1598 return new NullDriverLibrary();