| 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 | #include "WSI/VkSurfaceKHR.hpp" |
| 38 | #include "WSI/VkSwapchainKHR.hpp" |
| 39 | |
| 40 | #include <type_traits> |
| 41 | |
| 42 | namespace vk |
| 43 | { |
| 44 | |
| 45 | // Because Vulkan uses optional allocation callbacks, we use them in a custom |
| 46 | // placement new operator in the VkObjectBase class for simplicity. |
| 47 | // Unfortunately, since we use a placement new to allocate VkObjectBase derived |
| 48 | // classes objects, the corresponding deletion operator is a placement delete, |
| 49 | // which does nothing. In order to properly dispose of these objects' memory, |
| 50 | // we use this function, which calls the T:destroy() function then the T |
| 51 | // destructor prior to releasing the object (by default, |
| 52 | // VkObjectBase::destroy does nothing). |
| 53 | template<typename VkT> |
| 54 | inline void destroy(VkT vkObject, const VkAllocationCallbacks* pAllocator) |
| 55 | { |
| 56 | auto object = Cast(vkObject); |
| 57 | if(object) |
| 58 | { |
| 59 | using T = typename std::remove_pointer<decltype(object)>::type; |
| 60 | object->destroy(pAllocator); |
| 61 | object->~T(); |
| 62 | // object may not point to the same pointer as vkObject, for dispatchable objects, |
| 63 | // for example, so make sure to deallocate based on the vkObject pointer, which |
| 64 | // should always point to the beginning of the allocated memory |
| 65 | vk::deallocate(vkObject, pAllocator); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | |