1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "VkBuffer.hpp"
16 #include "VkBufferView.hpp"
17 #include "VkCommandBuffer.hpp"
18 #include "VkCommandPool.hpp"
19 #include "VkDevice.hpp"
20 #include "VkDeviceMemory.hpp"
21 #include "VkEvent.hpp"
22 #include "VkFence.hpp"
23 #include "VkFramebuffer.hpp"
24 #include "VkImage.hpp"
25 #include "VkImageView.hpp"
26 #include "VkInstance.hpp"
27 #include "VkPipeline.hpp"
28 #include "VkPipelineCache.hpp"
29 #include "VkPipelineLayout.hpp"
30 #include "VkPhysicalDevice.hpp"
31 #include "VkQueryPool.hpp"
32 #include "VkQueue.hpp"
33 #include "VkSampler.hpp"
34 #include "VkSemaphore.hpp"
35 #include "VkShaderModule.hpp"
36 #include "VkRenderPass.hpp"
37 
38 namespace vk
39 {
40 
41 // Because Vulkan uses optional allocation callbacks, we use them in a custom
42 // placement new operator in the VkObjectBase class for simplicity.
43 // Unfortunately, since we use a placement new to allocate VkObjectBase derived
44 // classes objects, the corresponding deletion operator is a placement delete,
45 // which does nothing. In order to properly dispose of these objects' memory,
46 // we use this function, which calls the proper T:destroy() function
47 // prior to releasing the object (by default, VkObjectBase::destroy does nothing).
48 template<typename VkT>
destroy(VkT vkObject,const VkAllocationCallbacks * pAllocator)49 inline void destroy(VkT vkObject, const VkAllocationCallbacks* pAllocator)
50 {
51 	auto object = Cast(vkObject);
52 	if(object)
53 	{
54 		object->destroy(pAllocator);
55 		// object may not point to the same pointer as vkObject, for dispatchable objects,
56 		// for example, so make sure to deallocate based on the vkObject pointer, which
57 		// should always point to the beginning of the allocated memory
58 		vk::deallocate(vkObject, pAllocator);
59 	}
60 }
61 
62 }
63