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