Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 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 | |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 18 | #include "Vulkan/VulkanPlatform.hpp" |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 19 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 20 | namespace vk { |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 21 | |
Nicolas Capens | 03fa329 | 2021-10-05 14:10:45 -0400 | [diff] [blame] | 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); |
Nicolas Capens | c329881 | 2021-10-05 14:31:31 -0400 | [diff] [blame] | 25 | void freeDeviceMemory(void *ptr); |
Nicolas Capens | 03fa329 | 2021-10-05 14:10:45 -0400 | [diff] [blame] | 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 | |
Nicolas Capens | c329881 | 2021-10-05 14:31:31 -0400 | [diff] [blame] | 31 | void *allocateHostMemory(size_t bytes, size_t alignment, const VkAllocationCallbacks *pAllocator, |
| 32 | VkSystemAllocationScope allocationScope); |
| 33 | void freeHostMemory(void *ptr, const VkAllocationCallbacks *pAllocator); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 34 | |
Antonio Maiorano | 71c49f8 | 2020-04-27 11:33:30 -0400 | [diff] [blame] | 35 | template<typename T> |
Nicolas Capens | c329881 | 2021-10-05 14:31:31 -0400 | [diff] [blame] | 36 | T *allocateHostmemory(size_t bytes, const VkAllocationCallbacks *pAllocator) |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 37 | { |
Nicolas Capens | c329881 | 2021-10-05 14:31:31 -0400 | [diff] [blame] | 38 | return static_cast<T *>(allocateHostMemory(bytes, alignof(T), pAllocator, T::GetAllocationScope())); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 41 | } // namespace vk |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 42 | |
Antonio Maiorano | 71c49f8 | 2020-04-27 11:33:30 -0400 | [diff] [blame] | 43 | #endif // VK_MEMORY_HPP_ |