Add very basic support for allocation callbacks to null driver
authorPyry Haulos <phaulos@google.com>
Fri, 11 Dec 2015 22:19:16 +0000 (14:19 -0800)
committerPyry Haulos <phaulos@google.com>
Wed, 16 Dec 2015 21:28:39 +0000 (13:28 -0800)
Change-Id: I174ce7df5099e5f79db88556008641ca54fdaaae

external/vulkancts/framework/vulkan/vkNullDriver.cpp
external/vulkancts/framework/vulkan/vkNullDriverImpl.inl
external/vulkancts/gen_framework.py

index 283f81d..b685974 100644 (file)
@@ -49,6 +49,101 @@ namespace
 
 using std::vector;
 
+// Memory management
+
+template<typename T>
+void* allocateSystemMem (const VkAllocationCallbacks* pAllocator, VkSystemAllocationScope scope)
+{
+       void* ptr = pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(T), sizeof(void*), scope);
+       if (!ptr)
+               throw std::bad_alloc();
+       return ptr;
+}
+
+void freeSystemMem (const VkAllocationCallbacks* pAllocator, void* mem)
+{
+       pAllocator->pfnFree(pAllocator->pUserData, mem);
+}
+
+template<typename Object, typename Handle, typename Parent, typename CreateInfo>
+Handle allocateHandle (Parent parent, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
+{
+       Object* obj = DE_NULL;
+
+       if (pAllocator)
+       {
+               void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+               try
+               {
+                       obj = new (mem) Object(parent, pCreateInfo);
+                       DE_ASSERT(obj == mem);
+               }
+               catch (...)
+               {
+                       pAllocator->pfnFree(pAllocator->pUserData, mem);
+                       throw;
+               }
+       }
+       else
+               obj = new Object(parent, pCreateInfo);
+
+       return reinterpret_cast<Handle>(obj);
+}
+
+template<typename Object, typename Handle, typename CreateInfo>
+Handle allocateHandle (const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
+{
+       Object* obj = DE_NULL;
+
+       if (pAllocator)
+       {
+               void* mem = allocateSystemMem<Object>(pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+               try
+               {
+                       obj = new (mem) Object(pCreateInfo);
+                       DE_ASSERT(obj == mem);
+               }
+               catch (...)
+               {
+                       pAllocator->pfnFree(pAllocator->pUserData, mem);
+                       throw;
+               }
+       }
+       else
+               obj = new Object(pCreateInfo);
+
+       return reinterpret_cast<Handle>(obj);
+}
+
+template<typename Object, typename Handle>
+void freeHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
+{
+       Object* obj = reinterpret_cast<Object*>(handle);
+
+       if (pAllocator)
+       {
+               obj->~Object();
+               freeSystemMem(pAllocator, reinterpret_cast<void*>(obj));
+       }
+       else
+               delete obj;
+}
+
+template<typename Object, typename Handle, typename CreateInfo>
+Handle allocateNonDispHandle (VkDevice device, const CreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
+{
+       Object* const   obj             = allocateHandle<Object, Object*>(device, pCreateInfo, pAllocator);
+       return Handle((deUint64)(deUintptr)obj);
+}
+
+template<typename Object, typename Handle>
+void freeNonDispHandle (Handle handle, const VkAllocationCallbacks* pAllocator)
+{
+       freeHandle<Object>(reinterpret_cast<Object*>((deUintptr)handle.getInternal()), pAllocator);
+}
+
+// Object definitions
+
 #define VK_NULL_RETURN(STMT)                                   \
        do {                                                                            \
                try {                                                                   \
@@ -271,6 +366,8 @@ void DescriptorPool::reset (void)
        m_managedSets.clear();
 }
 
+// API implementation
+
 extern "C"
 {
 
@@ -284,18 +381,56 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getDeviceProcAddr (VkDevice device, con
        return reinterpret_cast<Device*>(device)->getProcAddr(pName);
 }
 
-VKAPI_ATTR VkResult VKAPI_CALL createGraphicsPipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks*, VkPipeline* pPipelines)
+VKAPI_ATTR VkResult VKAPI_CALL createGraphicsPipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
 {
-       for (deUint32 ndx = 0; ndx < count; ndx++)
-               pPipelines[ndx] = VkPipeline((deUint64)(deUintptr)new Pipeline(device, pCreateInfos+ndx));
-       return VK_SUCCESS;
+       deUint32 allocNdx;
+       try
+       {
+               for (allocNdx = 0; allocNdx < count; allocNdx++)
+                       pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
+
+               return VK_SUCCESS;
+       }
+       catch (const std::bad_alloc&)
+       {
+               for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
+                       freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
+
+               return VK_ERROR_OUT_OF_HOST_MEMORY;
+       }
+       catch (VkResult err)
+       {
+               for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
+                       freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
+
+               return err;
+       }
 }
 
-VKAPI_ATTR VkResult VKAPI_CALL createComputePipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks*, VkPipeline* pPipelines)
+VKAPI_ATTR VkResult VKAPI_CALL createComputePipelines (VkDevice device, VkPipelineCache, deUint32 count, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
 {
-       for (deUint32 ndx = 0; ndx < count; ndx++)
-               pPipelines[ndx] = VkPipeline((deUint64)(deUintptr)new Pipeline(device, pCreateInfos+ndx));
-       return VK_SUCCESS;
+       deUint32 allocNdx;
+       try
+       {
+               for (allocNdx = 0; allocNdx < count; allocNdx++)
+                       pPipelines[allocNdx] = allocateNonDispHandle<Pipeline, VkPipeline>(device, pCreateInfos+allocNdx, pAllocator);
+
+               return VK_SUCCESS;
+       }
+       catch (const std::bad_alloc&)
+       {
+               for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
+                       freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
+
+               return VK_ERROR_OUT_OF_HOST_MEMORY;
+       }
+       catch (VkResult err)
+       {
+               for (deUint32 freeNdx = 0; freeNdx < allocNdx; freeNdx++)
+                       freeNonDispHandle<Pipeline, VkPipeline>(pPipelines[freeNdx], pAllocator);
+
+               return err;
+       }
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL enumeratePhysicalDevices (VkInstance, deUint32* pPhysicalDeviceCount, VkPhysicalDevice* pDevices)
index d3a627b..176b8a2 100644 (file)
 VKAPI_ATTR VkResult VKAPI_CALL createInstance (const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pInstance = reinterpret_cast<VkInstance>(new Instance(pCreateInfo)));
+       VK_NULL_RETURN((*pInstance = allocateHandle<Instance, VkInstance>(pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createDevice (VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pDevice = reinterpret_cast<VkDevice>(new Device(physicalDevice, pCreateInfo)));
+       VK_NULL_RETURN((*pDevice = allocateHandle<Device, VkDevice>(physicalDevice, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL allocateMemory (VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pMemory = VkDeviceMemory((deUint64)(deUintptr)new DeviceMemory(device, pAllocateInfo)));
+       VK_NULL_RETURN((*pMemory = allocateNonDispHandle<DeviceMemory, VkDeviceMemory>(device, pAllocateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createFence (VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pFence = VkFence((deUint64)(deUintptr)new Fence(device, pCreateInfo)));
+       VK_NULL_RETURN((*pFence = allocateNonDispHandle<Fence, VkFence>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createSemaphore (VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pSemaphore = VkSemaphore((deUint64)(deUintptr)new Semaphore(device, pCreateInfo)));
+       VK_NULL_RETURN((*pSemaphore = allocateNonDispHandle<Semaphore, VkSemaphore>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createEvent (VkDevice device, const VkEventCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkEvent* pEvent)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pEvent = VkEvent((deUint64)(deUintptr)new Event(device, pCreateInfo)));
+       VK_NULL_RETURN((*pEvent = allocateNonDispHandle<Event, VkEvent>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createQueryPool (VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pQueryPool = VkQueryPool((deUint64)(deUintptr)new QueryPool(device, pCreateInfo)));
+       VK_NULL_RETURN((*pQueryPool = allocateNonDispHandle<QueryPool, VkQueryPool>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createBuffer (VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pBuffer = VkBuffer((deUint64)(deUintptr)new Buffer(device, pCreateInfo)));
+       VK_NULL_RETURN((*pBuffer = allocateNonDispHandle<Buffer, VkBuffer>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createBufferView (VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pView = VkBufferView((deUint64)(deUintptr)new BufferView(device, pCreateInfo)));
+       VK_NULL_RETURN((*pView = allocateNonDispHandle<BufferView, VkBufferView>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createImage (VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pImage = VkImage((deUint64)(deUintptr)new Image(device, pCreateInfo)));
+       VK_NULL_RETURN((*pImage = allocateNonDispHandle<Image, VkImage>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createImageView (VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pView = VkImageView((deUint64)(deUintptr)new ImageView(device, pCreateInfo)));
+       VK_NULL_RETURN((*pView = allocateNonDispHandle<ImageView, VkImageView>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createShaderModule (VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pShaderModule = VkShaderModule((deUint64)(deUintptr)new ShaderModule(device, pCreateInfo)));
+       VK_NULL_RETURN((*pShaderModule = allocateNonDispHandle<ShaderModule, VkShaderModule>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createPipelineCache (VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pPipelineCache = VkPipelineCache((deUint64)(deUintptr)new PipelineCache(device, pCreateInfo)));
+       VK_NULL_RETURN((*pPipelineCache = allocateNonDispHandle<PipelineCache, VkPipelineCache>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createPipelineLayout (VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pPipelineLayout = VkPipelineLayout((deUint64)(deUintptr)new PipelineLayout(device, pCreateInfo)));
+       VK_NULL_RETURN((*pPipelineLayout = allocateNonDispHandle<PipelineLayout, VkPipelineLayout>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createSampler (VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pSampler = VkSampler((deUint64)(deUintptr)new Sampler(device, pCreateInfo)));
+       VK_NULL_RETURN((*pSampler = allocateNonDispHandle<Sampler, VkSampler>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createDescriptorSetLayout (VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pSetLayout = VkDescriptorSetLayout((deUint64)(deUintptr)new DescriptorSetLayout(device, pCreateInfo)));
+       VK_NULL_RETURN((*pSetLayout = allocateNonDispHandle<DescriptorSetLayout, VkDescriptorSetLayout>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createDescriptorPool (VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pDescriptorPool = VkDescriptorPool((deUint64)(deUintptr)new DescriptorPool(device, pCreateInfo)));
+       VK_NULL_RETURN((*pDescriptorPool = allocateNonDispHandle<DescriptorPool, VkDescriptorPool>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createFramebuffer (VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pFramebuffer = VkFramebuffer((deUint64)(deUintptr)new Framebuffer(device, pCreateInfo)));
+       VK_NULL_RETURN((*pFramebuffer = allocateNonDispHandle<Framebuffer, VkFramebuffer>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createRenderPass (VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pRenderPass = VkRenderPass((deUint64)(deUintptr)new RenderPass(device, pCreateInfo)));
+       VK_NULL_RETURN((*pRenderPass = allocateNonDispHandle<RenderPass, VkRenderPass>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL createCommandPool (VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
 {
        DE_UNREF(pAllocator);
-       VK_NULL_RETURN(*pCommandPool = VkCommandPool((deUint64)(deUintptr)new CommandPool(device, pCreateInfo)));
+       VK_NULL_RETURN((*pCommandPool = allocateNonDispHandle<CommandPool, VkCommandPool>(device, pCreateInfo, pAllocator)));
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyInstance (VkInstance instance, const VkAllocationCallbacks* pAllocator)
 {
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Instance*>(instance);
+       freeHandle<Instance, VkInstance>(instance, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyDevice (VkDevice device, const VkAllocationCallbacks* pAllocator)
 {
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Device*>(device);
+       freeHandle<Device, VkDevice>(device, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL freeMemory (VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<DeviceMemory*>((deUintptr)memory.getInternal());
+       freeNonDispHandle<DeviceMemory, VkDeviceMemory>(memory, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyFence (VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Fence*>((deUintptr)fence.getInternal());
+       freeNonDispHandle<Fence, VkFence>(fence, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroySemaphore (VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Semaphore*>((deUintptr)semaphore.getInternal());
+       freeNonDispHandle<Semaphore, VkSemaphore>(semaphore, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyEvent (VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Event*>((deUintptr)event.getInternal());
+       freeNonDispHandle<Event, VkEvent>(event, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyQueryPool (VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<QueryPool*>((deUintptr)queryPool.getInternal());
+       freeNonDispHandle<QueryPool, VkQueryPool>(queryPool, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyBuffer (VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Buffer*>((deUintptr)buffer.getInternal());
+       freeNonDispHandle<Buffer, VkBuffer>(buffer, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyBufferView (VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<BufferView*>((deUintptr)bufferView.getInternal());
+       freeNonDispHandle<BufferView, VkBufferView>(bufferView, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyImage (VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Image*>((deUintptr)image.getInternal());
+       freeNonDispHandle<Image, VkImage>(image, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyImageView (VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<ImageView*>((deUintptr)imageView.getInternal());
+       freeNonDispHandle<ImageView, VkImageView>(imageView, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyShaderModule (VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<ShaderModule*>((deUintptr)shaderModule.getInternal());
+       freeNonDispHandle<ShaderModule, VkShaderModule>(shaderModule, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyPipelineCache (VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<PipelineCache*>((deUintptr)pipelineCache.getInternal());
+       freeNonDispHandle<PipelineCache, VkPipelineCache>(pipelineCache, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyPipeline (VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Pipeline*>((deUintptr)pipeline.getInternal());
+       freeNonDispHandle<Pipeline, VkPipeline>(pipeline, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyPipelineLayout (VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<PipelineLayout*>((deUintptr)pipelineLayout.getInternal());
+       freeNonDispHandle<PipelineLayout, VkPipelineLayout>(pipelineLayout, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroySampler (VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Sampler*>((deUintptr)sampler.getInternal());
+       freeNonDispHandle<Sampler, VkSampler>(sampler, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyDescriptorSetLayout (VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<DescriptorSetLayout*>((deUintptr)descriptorSetLayout.getInternal());
+       freeNonDispHandle<DescriptorSetLayout, VkDescriptorSetLayout>(descriptorSetLayout, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyDescriptorPool (VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<DescriptorPool*>((deUintptr)descriptorPool.getInternal());
+       freeNonDispHandle<DescriptorPool, VkDescriptorPool>(descriptorPool, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyFramebuffer (VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<Framebuffer*>((deUintptr)framebuffer.getInternal());
+       freeNonDispHandle<Framebuffer, VkFramebuffer>(framebuffer, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyRenderPass (VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<RenderPass*>((deUintptr)renderPass.getInternal());
+       freeNonDispHandle<RenderPass, VkRenderPass>(renderPass, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL destroyCommandPool (VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
 {
        DE_UNREF(device);
-       DE_UNREF(pAllocator);
-       delete reinterpret_cast<CommandPool*>((deUintptr)commandPool.getInternal());
+       freeNonDispHandle<CommandPool, VkCommandPool>(commandPool, pAllocator);
 }
 
 VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceFeatures (VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
index e889007..17cafe3 100644 (file)
@@ -674,16 +674,16 @@ def writeNullDriverImpl (api, filename):
 
                for function in createFuncs:
                        objectType      = function.arguments[-1].type.replace("*", "").strip()
-                       argsStr         = ", ".join([a.name for a in function.arguments[:-2]])
+                       argsStr         = ", ".join([a.name for a in function.arguments[:-1]])
 
                        yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
                        yield "{"
                        yield "\tDE_UNREF(%s);" % function.arguments[-2].name
 
                        if getHandle(objectType).type == Handle.TYPE_NONDISP:
-                               yield "\tVK_NULL_RETURN(*%s = %s((deUint64)(deUintptr)new %s(%s)));" % (function.arguments[-1].name, objectType, objectType[2:], argsStr)
+                               yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
                        else:
-                               yield "\tVK_NULL_RETURN(*%s = reinterpret_cast<%s>(new %s(%s)));" % (function.arguments[-1].name, objectType, objectType[2:], argsStr)
+                               yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
 
                        yield "}"
                        yield ""
@@ -695,12 +695,11 @@ def writeNullDriverImpl (api, filename):
                        yield "{"
                        for arg in function.arguments[:-2]:
                                yield "\tDE_UNREF(%s);" % arg.name
-                       yield "\tDE_UNREF(%s);" % function.arguments[-1].name
 
                        if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
-                               yield "\tdelete reinterpret_cast<%s*>((deUintptr)%s.getInternal());" % (objectArg.type[2:], objectArg.name)
+                               yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
                        else:
-                               yield "\tdelete reinterpret_cast<%s*>(%s);" % (objectArg.type[2:], objectArg.name)
+                               yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
 
                        yield "}"
                        yield ""