dEQP-VK.renderpass: Set IMAGE_USAGE_TRANSFER_SRC_BIT when needed
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkNullDriver.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and/or associated documentation files (the
9  * "Materials"), to deal in the Materials without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Materials, and to
12  * permit persons to whom the Materials are furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice(s) and this permission notice shall be
16  * included in all copies or substantial portions of the Materials.
17  *
18  * The Materials are Confidential Information as defined by the
19  * Khronos Membership Agreement until designated non-confidential by
20  * Khronos, at which point this condition clause shall be removed.
21  *
22  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
29  *
30  *//*!
31  * \file
32  * \brief Null (dummy) Vulkan implementation.
33  *//*--------------------------------------------------------------------*/
34
35 #include "vkNullDriver.hpp"
36 #include "vkPlatform.hpp"
37 #include "vkImageUtil.hpp"
38 #include "tcuFunctionLibrary.hpp"
39 #include "deMemory.h"
40
41 #include <stdexcept>
42 #include <algorithm>
43
44 namespace vk
45 {
46
47 namespace
48 {
49
50 using std::vector;
51
52 // Memory management
53
54 template<typename T>
55 void* allocateSystemMem (const VkAllocationCallbacks* pAllocator, VkSystemAllocationScope scope)
56 {
57         void* ptr = pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(T), sizeof(void*), scope);
58         if (!ptr)
59                 throw std::bad_alloc();
60         return ptr;
61 }
62
63 void freeSystemMem (const VkAllocationCallbacks* pAllocator, void* mem)
64 {
65         pAllocator->pfnFree(pAllocator->pUserData, mem);
66 }
67
68 template<typename Object, typename Handle, typename Parent, typename CreateInfo>
69 Handle allocateHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
70 {
71         Object* obj = DE_NULL;
72
73         if (pAllocator)
74         {
75                 void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
76                 try
77                 {
78                         obj = new (mem) Object(parent, pCreateInfo);
79                         DE_ASSERT(obj == mem);
80                 }
81                 catch (...)
82                 {
83                         pAllocator->pfnFree(pAllocator->pUserData, mem);
84                         throw;
85                 }
86         }
87         else
88                 obj = new Object(parent, pCreateInfo);
89
90         return reinterpret_cast<Handle>(obj);
91 }
92
93 template<typename Object, typename Handle, typename CreateInfo>
94 Handle allocateHandle (const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
95 {
96         Object* obj = DE_NULL;
97
98         if (pAllocator)
99         {
100                 void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
101                 try
102                 {
103                         obj = new (mem) Object(pCreateInfo);
104                         DE_ASSERT(obj == mem);
105                 }
106                 catch (...)
107                 {
108                         pAllocator->pfnFree(pAllocator->pUserData, mem);
109                         throw;
110                 }
111         }
112         else
113                 obj = new Object(pCreateInfo);
114
115         return reinterpret_cast<Handle>(obj);
116 }
117
118 template<typename Object, typename Handle>
119 void freeHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
120 {
121         Object* obj = reinterpret_cast<Object*>(handle);
122
123         if (pAllocator)
124         {
125                 obj->~Object();
126                 freeSystemMem(pAllocator, reinterpret_cast<void*>(obj));
127         }
128         else
129                 delete obj;
130 }
131
132 template<typename Object, typename Handle, typename CreateInfo>
133 Handle allocateNonDispHandle (VkDevice device, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
134 {
135         Object* const   obj             = allocateHandle<Object, Object*>(device, pCreateInfo, pAllocator);
136         return Handle((deUint64)(deUintptr)obj);
137 }
138
139 template<typename Object, typename Handle>
140 void freeNonDispHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
141 {
142         freeHandle<Object>(reinterpret_cast<Object*>((deUintptr)handle.getInternal()), pAllocator);
143 }
144
145 // Object definitions
146
147 #define VK_NULL_RETURN(STMT)                                    \
148         do {                                                                            \
149                 try {                                                                   \
150                         STMT;                                                           \
151                         return VK_SUCCESS;                                      \
152                 } catch (const std::bad_alloc&) {               \
153                         return VK_ERROR_OUT_OF_HOST_MEMORY;     \
154                 } catch (VkResult res) {                                \
155                         return res;                                                     \
156                 }                                                                               \
157         } while (deGetFalse())
158
159 // \todo [2015-07-14 pyry] Check FUNC type by checkedCastToPtr<T>() or similar
160 #define VK_NULL_FUNC_ENTRY(NAME, FUNC)  { #NAME, (deFunctionPtr)FUNC }
161
162 #define VK_NULL_DEFINE_DEVICE_OBJ(NAME)                         \
163 struct NAME                                                                                     \
164 {                                                                                                       \
165         NAME (VkDevice, const Vk##NAME##CreateInfo*) {} \
166 }
167
168 VK_NULL_DEFINE_DEVICE_OBJ(Fence);
169 VK_NULL_DEFINE_DEVICE_OBJ(Semaphore);
170 VK_NULL_DEFINE_DEVICE_OBJ(Event);
171 VK_NULL_DEFINE_DEVICE_OBJ(QueryPool);
172 VK_NULL_DEFINE_DEVICE_OBJ(BufferView);
173 VK_NULL_DEFINE_DEVICE_OBJ(ImageView);
174 VK_NULL_DEFINE_DEVICE_OBJ(ShaderModule);
175 VK_NULL_DEFINE_DEVICE_OBJ(PipelineCache);
176 VK_NULL_DEFINE_DEVICE_OBJ(PipelineLayout);
177 VK_NULL_DEFINE_DEVICE_OBJ(RenderPass);
178 VK_NULL_DEFINE_DEVICE_OBJ(DescriptorSetLayout);
179 VK_NULL_DEFINE_DEVICE_OBJ(Sampler);
180 VK_NULL_DEFINE_DEVICE_OBJ(Framebuffer);
181 VK_NULL_DEFINE_DEVICE_OBJ(CommandPool);
182
183 class Instance
184 {
185 public:
186                                                                                 Instance                (const VkInstanceCreateInfo* instanceInfo);
187                                                                                 ~Instance               (void) {}
188
189         PFN_vkVoidFunction                                      getProcAddr             (const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
190
191 private:
192         const tcu::StaticFunctionLibrary        m_functions;
193 };
194
195 class Device
196 {
197 public:
198                                                                                 Device                  (VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* deviceInfo);
199                                                                                 ~Device                 (void) {}
200
201         PFN_vkVoidFunction                                      getProcAddr             (const char* name) const { return (PFN_vkVoidFunction)m_functions.getFunction(name); }
202
203 private:
204         const tcu::StaticFunctionLibrary        m_functions;
205 };
206
207 class Pipeline
208 {
209 public:
210         Pipeline (VkDevice, const VkGraphicsPipelineCreateInfo*) {}
211         Pipeline (VkDevice, const VkComputePipelineCreateInfo*) {}
212 };
213
214 void* allocateHeap (const VkMemoryAllocateInfo* pAllocInfo)
215 {
216         // \todo [2015-12-03 pyry] Alignment requirements?
217         // \todo [2015-12-03 pyry] Empty allocations okay?
218         if (pAllocInfo->allocationSize > 0)
219         {
220                 void* const heapPtr = deMalloc((size_t)pAllocInfo->allocationSize);
221                 if (!heapPtr)
222                         throw std::bad_alloc();
223                 return heapPtr;
224         }
225         else
226                 return DE_NULL;
227 }
228
229 void freeHeap (void* ptr)
230 {
231         deFree(ptr);
232 }
233
234 class DeviceMemory
235 {
236 public:
237                                                 DeviceMemory    (VkDevice, const VkMemoryAllocateInfo* pAllocInfo)
238                                                         : m_memory(allocateHeap(pAllocInfo))
239                                                 {
240                                                 }
241                                                 ~DeviceMemory   (void)
242                                                 {
243                                                         freeHeap(m_memory);
244                                                 }
245
246         void*                           getPtr                  (void) const { return m_memory; }
247
248 private:
249         void* const                     m_memory;
250 };
251
252 class Buffer
253 {
254 public:
255                                                 Buffer          (VkDevice, const VkBufferCreateInfo* pCreateInfo)
256                                                         : m_size(pCreateInfo->size)
257                                                 {}
258
259         VkDeviceSize            getSize         (void) const { return m_size;   }
260
261 private:
262         const VkDeviceSize      m_size;
263 };
264
265 class Image
266 {
267 public:
268                                                                 Image                   (VkDevice, const VkImageCreateInfo* pCreateInfo)
269                                                                         : m_imageType   (pCreateInfo->imageType)
270                                                                         , m_format              (pCreateInfo->format)
271                                                                         , m_extent              (pCreateInfo->extent)
272                                                                         , m_samples             (pCreateInfo->samples)
273                                                                 {}
274
275         VkImageType                                     getImageType    (void) const { return m_imageType;      }
276         VkFormat                                        getFormat               (void) const { return m_format;         }
277         VkExtent3D                                      getExtent               (void) const { return m_extent;         }
278         VkSampleCountFlagBits           getSamples              (void) const { return m_samples;        }
279
280 private:
281         const VkImageType                       m_imageType;
282         const VkFormat                          m_format;
283         const VkExtent3D                        m_extent;
284         const VkSampleCountFlagBits     m_samples;
285 };
286
287 class CommandBuffer
288 {
289 public:
290                                                 CommandBuffer(VkDevice, VkCommandPool, VkCommandBufferLevel)
291                                                 {}
292 };
293
294 class DescriptorSet
295 {
296 public:
297         DescriptorSet (VkDevice, VkDescriptorPool, VkDescriptorSetLayout) {}
298 };
299
300 class DescriptorPool
301 {
302 public:
303                                                                                 DescriptorPool  (VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo)
304                                                                                         : m_device      (device)
305                                                                                         , m_flags       (pCreateInfo->flags)
306                                                                                 {}
307                                                                                 ~DescriptorPool (void)
308                                                                                 {
309                                                                                         reset();
310                                                                                 }
311
312         VkDescriptorSet                                         allocate                (VkDescriptorSetLayout setLayout);
313         void                                                            free                    (VkDescriptorSet set);
314
315         void                                                            reset                   (void);
316
317 private:
318         const VkDevice                                          m_device;
319         const VkDescriptorPoolCreateFlags       m_flags;
320
321         vector<DescriptorSet*>                          m_managedSets;
322 };
323
324 VkDescriptorSet DescriptorPool::allocate (VkDescriptorSetLayout setLayout)
325 {
326         DescriptorSet* const    impl    = new DescriptorSet(m_device, VkDescriptorPool(reinterpret_cast<deUintptr>(this)), setLayout);
327
328         try
329         {
330                 m_managedSets.push_back(impl);
331         }
332         catch (...)
333         {
334                 delete impl;
335                 throw;
336         }
337
338         return VkDescriptorSet(reinterpret_cast<deUintptr>(impl));
339 }
340
341 void DescriptorPool::free (VkDescriptorSet set)
342 {
343         DescriptorSet* const    impl    = reinterpret_cast<DescriptorSet*>((deUintptr)set.getInternal());
344
345         DE_ASSERT(m_flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT);
346
347         delete impl;
348
349         for (size_t ndx = 0; ndx < m_managedSets.size(); ++ndx)
350         {
351                 if (m_managedSets[ndx] == impl)
352                 {
353                         std::swap(m_managedSets[ndx], m_managedSets.back());
354                         m_managedSets.pop_back();
355                         return;
356                 }
357         }
358
359         DE_FATAL("VkDescriptorSet not owned by VkDescriptorPool");
360 }
361
362 void DescriptorPool::reset (void)
363 {
364         for (size_t ndx = 0; ndx < m_managedSets.size(); ++ndx)
365                 delete m_managedSets[ndx];
366         m_managedSets.clear();
367 }
368
369 // API implementation
370
371 extern "C"
372 {
373
374 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName)
375 {
376         return reinterpret_cast<Instance*>(instance)->getProcAddr(pName);
377 }
378
379 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getDeviceProcAddr (VkDevice device, const char* pName)
380 {
381         return reinterpret_cast<Device*>(device)->getProcAddr(pName);
382 }
383
384 VKAPI_ATTR VkResult VKAPI_CALL createGraphicsPipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
385 {
386         deUint32 allocNdx;
387         try
388         {
389                 for (allocNdx = 0; allocNdx < count; allocNdx++)
390                         pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
391
392                 return VK_SUCCESS;
393         }
394         catch (const std::bad_alloc&)
395         {
396                 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
397                         freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
398
399                 return VK_ERROR_OUT_OF_HOST_MEMORY;
400         }
401         catch (VkResult err)
402         {
403                 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
404                         freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
405
406                 return err;
407         }
408 }
409
410 VKAPI_ATTR VkResult VKAPI_CALL createComputePipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
411 {
412         deUint32 allocNdx;
413         try
414         {
415                 for (allocNdx = 0; allocNdx < count; allocNdx++)
416                         pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
417
418                 return VK_SUCCESS;
419         }
420         catch (const std::bad_alloc&)
421         {
422                 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
423                         freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
424
425                 return VK_ERROR_OUT_OF_HOST_MEMORY;
426         }
427         catch (VkResult err)
428         {
429                 for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
430                         freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
431
432                 return err;
433         }
434 }
435
436 VKAPI_ATTR VkResult VKAPI_CALL enumeratePhysicalDevices (VkInstance, deUint32* pPhysicalDeviceCount, VkPhysicalDevice* pDevices)
437 {
438         if (pDevices && *pPhysicalDeviceCount >= 1u)
439                 *pDevices = reinterpret_cast<VkPhysicalDevice>((void*)(deUintptr)1u);
440
441         *pPhysicalDeviceCount = 1;
442
443         return VK_SUCCESS;
444 }
445
446 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceProperties (VkPhysicalDevice, VkPhysicalDeviceProperties* props)
447 {
448         deMemset(props, 0, sizeof(VkPhysicalDeviceProperties));
449
450         props->apiVersion               = VK_API_VERSION;
451         props->driverVersion    = 1u;
452         props->deviceType               = VK_PHYSICAL_DEVICE_TYPE_OTHER;
453
454         deMemcpy(props->deviceName, "null", 5);
455
456         // \todo [2015-09-25 pyry] Fill in reasonable limits
457         props->limits.maxTexelBufferElements    = 8096;
458 }
459
460 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceQueueFamilyProperties (VkPhysicalDevice, deUint32* count, VkQueueFamilyProperties* props)
461 {
462         if (props && *count >= 1u)
463         {
464                 deMemset(props, 0, sizeof(VkQueueFamilyProperties));
465
466                 props->queueCount                       = 1u;
467                 props->queueFlags                       = VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT;
468                 props->timestampValidBits       = 64;
469         }
470
471         *count = 1u;
472 }
473
474 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceMemoryProperties (VkPhysicalDevice, VkPhysicalDeviceMemoryProperties* props)
475 {
476         deMemset(props, 0, sizeof(VkPhysicalDeviceMemoryProperties));
477
478         props->memoryTypeCount                          = 1u;
479         props->memoryTypes[0].heapIndex         = 0u;
480         props->memoryTypes[0].propertyFlags     = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
481
482         props->memoryHeapCount                          = 1u;
483         props->memoryHeaps[0].size                      = 1ull << 31;
484         props->memoryHeaps[0].flags                     = 0u;
485 }
486
487 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceFormatProperties (VkPhysicalDevice, VkFormat, VkFormatProperties* pFormatProperties)
488 {
489         const VkFormatFeatureFlags      allFeatures     = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
490                                                                                         | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
491                                                                                         | VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
492                                                                                         | VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
493                                                                                         | VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
494                                                                                         | VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
495                                                                                         | VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
496                                                                                         | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
497                                                                                         | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
498                                                                                         | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
499                                                                                         | VK_FORMAT_FEATURE_BLIT_SRC_BIT
500                                                                                         | VK_FORMAT_FEATURE_BLIT_DST_BIT;
501
502         pFormatProperties->linearTilingFeatures         = allFeatures;
503         pFormatProperties->optimalTilingFeatures        = allFeatures;
504         pFormatProperties->bufferFeatures                       = allFeatures;
505 }
506
507 VKAPI_ATTR void VKAPI_CALL getBufferMemoryRequirements (VkDevice, VkBuffer bufferHandle, VkMemoryRequirements* requirements)
508 {
509         const Buffer*   buffer  = reinterpret_cast<const Buffer*>(bufferHandle.getInternal());
510
511         requirements->memoryTypeBits    = 1u;
512         requirements->size                              = buffer->getSize();
513         requirements->alignment                 = (VkDeviceSize)1u;
514 }
515
516 VKAPI_ATTR VkDeviceSize VKAPI_CALL getPackedImageDataSize (VkFormat format, VkExtent3D extent, VkSampleCountFlagBits samples)
517 {
518         return (VkDeviceSize)getPixelSize(mapVkFormat(format))
519                         * (VkDeviceSize)extent.width
520                         * (VkDeviceSize)extent.height
521                         * (VkDeviceSize)extent.depth
522                         * (VkDeviceSize)samples;
523 }
524
525 VKAPI_ATTR void VKAPI_CALL getImageMemoryRequirements (VkDevice, VkImage imageHandle, VkMemoryRequirements* requirements)
526 {
527         const Image*    image   = reinterpret_cast<const Image*>(imageHandle.getInternal());
528
529         requirements->memoryTypeBits    = 1u;
530         requirements->alignment                 = 4u;
531         requirements->size                              = getPackedImageDataSize(image->getFormat(), image->getExtent(), image->getSamples());
532 }
533
534 VKAPI_ATTR VkResult VKAPI_CALL mapMemory (VkDevice, VkDeviceMemory memHandle, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData)
535 {
536         const DeviceMemory*     memory  = reinterpret_cast<DeviceMemory*>(memHandle.getInternal());
537
538         DE_UNREF(size);
539         DE_UNREF(flags);
540
541         *ppData = (deUint8*)memory->getPtr() + offset;
542
543         return VK_SUCCESS;
544 }
545
546 VKAPI_ATTR VkResult VKAPI_CALL allocateDescriptorSets (VkDevice, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
547 {
548         DescriptorPool* const   poolImpl        = reinterpret_cast<DescriptorPool*>((deUintptr)pAllocateInfo->descriptorPool.getInternal());
549
550         for (deUint32 ndx = 0; ndx < pAllocateInfo->setLayoutCount; ++ndx)
551         {
552                 try
553                 {
554                         pDescriptorSets[ndx] = poolImpl->allocate(pAllocateInfo->pSetLayouts[ndx]);
555                 }
556                 catch (const std::bad_alloc&)
557                 {
558                         for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
559                                 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
560
561                         return VK_ERROR_OUT_OF_HOST_MEMORY;
562                 }
563                 catch (VkResult res)
564                 {
565                         for (deUint32 freeNdx = 0; freeNdx < ndx; freeNdx++)
566                                 delete reinterpret_cast<DescriptorSet*>((deUintptr)pDescriptorSets[freeNdx].getInternal());
567
568                         return res;
569                 }
570         }
571
572         return VK_SUCCESS;
573 }
574
575 VKAPI_ATTR void VKAPI_CALL freeDescriptorSets (VkDevice, VkDescriptorPool descriptorPool, deUint32 count, const VkDescriptorSet* pDescriptorSets)
576 {
577         DescriptorPool* const   poolImpl        = reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
578
579         for (deUint32 ndx = 0; ndx < count; ++ndx)
580                 poolImpl->free(pDescriptorSets[ndx]);
581 }
582
583 VKAPI_ATTR VkResult VKAPI_CALL resetDescriptorPool (VkDevice, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags)
584 {
585         DescriptorPool* const   poolImpl        = reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
586
587         poolImpl->reset();
588
589         return VK_SUCCESS;
590 }
591
592 VKAPI_ATTR VkResult VKAPI_CALL allocateCommandBuffers (VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
593 {
594         if (pAllocateInfo && pCommandBuffers)
595         {
596                 for (deUint32 ndx = 0; ndx < pAllocateInfo->bufferCount; ++ndx)
597                 {
598                         pCommandBuffers[ndx] = reinterpret_cast<VkCommandBuffer>(new CommandBuffer(device, pAllocateInfo->commandPool, pAllocateInfo->level));
599                 }
600         }
601
602         return VK_SUCCESS;
603 }
604
605 VKAPI_ATTR void VKAPI_CALL freeCommandBuffers (VkDevice device, VkCommandPool commandPool, deUint32 commandBufferCount, const VkCommandBuffer* pCommandBuffers)
606 {
607         DE_UNREF(device);
608         DE_UNREF(commandPool);
609
610         for (deUint32 ndx = 0; ndx < commandBufferCount; ++ndx)
611                 delete reinterpret_cast<CommandBuffer*>(pCommandBuffers[ndx]);
612 }
613
614 #include "vkNullDriverImpl.inl"
615
616 } // extern "C"
617
618 Instance::Instance (const VkInstanceCreateInfo*)
619         : m_functions(s_instanceFunctions, DE_LENGTH_OF_ARRAY(s_instanceFunctions))
620 {
621 }
622
623 Device::Device (VkPhysicalDevice, const VkDeviceCreateInfo*)
624         : m_functions(s_deviceFunctions, DE_LENGTH_OF_ARRAY(s_deviceFunctions))
625 {
626 }
627
628 class NullDriverLibrary : public Library
629 {
630 public:
631                                                                                 NullDriverLibrary (void)
632                                                                                         : m_library     (s_platformFunctions, DE_LENGTH_OF_ARRAY(s_platformFunctions))
633                                                                                         , m_driver      (m_library)
634                                                                                 {}
635
636         const PlatformInterface&                        getPlatformInterface    (void) const { return m_driver; }
637
638 private:
639         const tcu::StaticFunctionLibrary        m_library;
640         const PlatformDriver                            m_driver;
641 };
642
643 } // anonymous
644
645 Library* createNullDriver (void)
646 {
647         return new NullDriverLibrary();
648 }
649
650 } // vk