blob: 990df7db655bfef8a1d8aa4096b4bf2299880e05 [file] [log] [blame]
Alexis Hetu767b41b2018-09-26 11:25:46 -04001// 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 Maiorano42fd1592020-04-27 11:30:40 -040018#include "Vulkan/VulkanPlatform.hpp"
Alexis Hetu767b41b2018-09-26 11:25:46 -040019
Nicolas Capens157ba262019-12-10 17:49:14 -050020namespace vk {
Alexis Hetu767b41b2018-09-26 11:25:46 -040021
Nicolas Capens03fa3292021-10-05 14:10:45 -040022// TODO(b/192449828): Pass VkDeviceDeviceMemoryReportCreateInfoEXT into these functions to
23// centralize device memory report callback usage.
24void *allocateDeviceMemory(size_t bytes, size_t alignment);
Nicolas Capensc3298812021-10-05 14:31:31 -040025void freeDeviceMemory(void *ptr);
Nicolas Capens03fa3292021-10-05 14:10:45 -040026
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.
29constexpr VkAllocationCallbacks *NULL_ALLOCATION_CALLBACKS = nullptr;
30
Nicolas Capensc3298812021-10-05 14:31:31 -040031void *allocateHostMemory(size_t bytes, size_t alignment, const VkAllocationCallbacks *pAllocator,
32 VkSystemAllocationScope allocationScope);
33void freeHostMemory(void *ptr, const VkAllocationCallbacks *pAllocator);
Alexis Hetu767b41b2018-09-26 11:25:46 -040034
Antonio Maiorano71c49f82020-04-27 11:33:30 -040035template<typename T>
Nicolas Capensc3298812021-10-05 14:31:31 -040036T *allocateHostmemory(size_t bytes, const VkAllocationCallbacks *pAllocator)
Alexis Hetu767b41b2018-09-26 11:25:46 -040037{
Nicolas Capensc3298812021-10-05 14:31:31 -040038 return static_cast<T *>(allocateHostMemory(bytes, alignof(T), pAllocator, T::GetAllocationScope()));
Alexis Hetu767b41b2018-09-26 11:25:46 -040039}
40
Nicolas Capens157ba262019-12-10 17:49:14 -050041} // namespace vk
Alexis Hetu767b41b2018-09-26 11:25:46 -040042
Antonio Maiorano71c49f82020-04-27 11:33:30 -040043#endif // VK_MEMORY_HPP_