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 #ifndef VK_MEMORY_HPP_
16 #define VK_MEMORY_HPP_
17
18 #include "Vulkan/VulkanPlatform.hpp"
19
20 namespace vk {
21
22 // TODO(b/192449828): Pass VkDeviceDeviceMemoryReportCreateInfoEXT into these functions to
23 // centralize device memory report callback usage.
24 void *allocateDeviceMemory(size_t bytes, size_t alignment);
25 void freeDeviceMemory(void *ptr);
26
27 // TODO(b/201798871): Fix host allocation callback usage. Uses of this symbolic constant indicate
28 // places where we should use an allocator instead of unaccounted memory allocations.
29 constexpr VkAllocationCallbacks *NULL_ALLOCATION_CALLBACKS = nullptr;
30
31 void *allocateHostMemory(size_t bytes, size_t alignment, const VkAllocationCallbacks *pAllocator,
32 VkSystemAllocationScope allocationScope);
33 void freeHostMemory(void *ptr, const VkAllocationCallbacks *pAllocator);
34
35 template<typename T>
allocateHostmemory(size_t bytes,const VkAllocationCallbacks * pAllocator)36 T *allocateHostmemory(size_t bytes, const VkAllocationCallbacks *pAllocator)
37 {
38 return static_cast<T *>(allocateHostMemory(bytes, alignof(T), pAllocator, T::GetAllocationScope()));
39 }
40
41 } // namespace vk
42
43 #endif // VK_MEMORY_HPP_
44