59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
#pragma once
|
|
|
|
/* #include "vulkan_util.hpp" */
|
|
#include <gz-util/log.hpp>
|
|
|
|
#include <initializer_list>
|
|
#include <vulkan/vulkan.hpp>
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
#include <list>
|
|
#include <map>
|
|
|
|
/* #include <vulkan/vulkan_core.h> */
|
|
|
|
namespace gz::vk {
|
|
struct MemoryInfo {
|
|
VkDeviceMemory memory = VK_NULL_HANDLE;
|
|
VkDeviceSize offset = 0;
|
|
uint32_t memoryTypeIndex = 0;
|
|
};
|
|
// if no memory is available, allocate a chunk of multiplier * requested size
|
|
constexpr VkDeviceSize TODO_ALLOCATION_SIZE_MULTIPLIIER = 10;
|
|
|
|
|
|
// defined in vulkan_instance.hpp
|
|
class VulkanInstance;
|
|
// defined in vulkan_allocator.cpp
|
|
struct DeviceMemory;
|
|
|
|
class VulkanAllocator {
|
|
public:
|
|
VulkanAllocator(VulkanInstance& instance);
|
|
/**
|
|
* @brief Get a block from a VkDeviceMemory
|
|
* @details
|
|
* Get a block of allocI.allocationSize of a VkDeviceMemory that was allocated with allocI.memoryTypeIndex.
|
|
*
|
|
* When this function returns, memoryInfo will contain the information about the available block.
|
|
* You can then bind something of size allocI.allocationSize to memoryInfo.memory at offset memoryInfo.offset.
|
|
* @throws VkException when a call to vkAllocateMemory is needed and fails
|
|
* @todo Determine the size of new allocations
|
|
*/
|
|
void allocate(const VkMemoryAllocateInfo& allocI, MemoryInfo& memoryInfo);
|
|
/**
|
|
* @brief Free a block allocated with allocate()
|
|
*
|
|
* When this function returns, memoryInfo will be reset to default values
|
|
* @throws VkUserError if memoryInfo was not allocated from this allocator
|
|
*/
|
|
void free(MemoryInfo& memoryInfo);
|
|
private:
|
|
/// allocated memory for memoryIndexType
|
|
std::map<uint32_t, std::vector<DeviceMemory>> memory;
|
|
Log aLog;
|
|
VulkanInstance& vk;
|
|
|
|
}; // class VulkanAllocator
|
|
} // namespace gz::vk
|