nngn
|
Manages device memory queries, allocations, and lifetime. More...
#include <memory.h>
Public Types | |
template<VkMemoryPropertyFlags f> | |
using | find_ret = std::conditional_t<required(f), void, bool> |
Public Member Functions | |
DeviceMemory (void)=default | |
~DeviceMemory (void) | |
bool | init (VkInstance inst, VkPhysicalDevice physical_dev, VkDevice dev) |
template<VkMemoryPropertyFlags f> | |
find_ret< f > | find_type (std::uint32_t type, std::uint32_t *p) const |
Finds a memory type among those offered by the device. | |
template<VkMemoryPropertyFlags f> | |
bool | alloc (const VkMemoryRequirements *req, VkDeviceMemory *p) |
Allocates device memory from a type that fulfills req . | |
template<VkMemoryPropertyFlags f> | |
bool | alloc (const VkMemoryRequirements *req, MemoryAllocation *alloc, VkDeviceMemory *mem, VkDeviceSize *offset) |
Allocates device memory from a type that fulfills req . | |
template<VkMemoryPropertyFlags f> | |
bool | alloc (VkBuffer buf, VkDeviceMemory *p) |
Allocates device memory from a type for a given buffer. | |
template<VkMemoryPropertyFlags f> | |
bool | alloc (VkBuffer b, MemoryAllocation *alloc, VkDeviceMemory *mem, VkDeviceSize *offset) |
Allocates device memory from a type that fulfills req . | |
template<VkMemoryPropertyFlags f> | |
bool | alloc (VkImage img, VkDeviceMemory *p) |
Allocates device memory from a type for a given image. | |
template<VkMemoryPropertyFlags f> | |
bool | alloc (VkImage img, MemoryAllocation *alloc, VkDeviceMemory *mem, VkDeviceSize *offset) |
Allocates device memory from a type for a given image. | |
void | dealloc (VkDeviceMemory mem) |
Deallocates a block of device memory. | |
void | dealloc (MemoryAllocation alloc) |
Deallocates a block of memory from an allocation pool (if necessary). | |
template<VkMemoryPropertyFlags f> | |
auto | find_type (std::uint32_t type, std::uint32_t *p) const -> find_ret< f > |
Static Public Member Functions | |
static constexpr bool | required (VkMemoryPropertyFlags f) |
Indicates whether a memory type is guaranteed to exist. | |
Private Member Functions | |
bool | alloc (std::uint32_t type, VkDeviceSize size, VkDeviceMemory *p) |
Shared implementation for all dedicated allocations. | |
bool | alloc (std::uint32_t type, const VkMemoryRequirements *req, MemoryAllocation *alloc, VkDeviceMemory *mem, VkDeviceSize *offset) |
Shared implementation for all pooled allocations. | |
Private Attributes | |
VkDevice | dev = {} |
void * | allocator = {} |
VkPhysicalDeviceMemoryProperties | props = {} |
Manages device memory queries, allocations, and lifetime.
using nngn::DeviceMemory::find_ret = std::conditional_t<required(f), void, bool> |
|
default |
nngn::DeviceMemory::~DeviceMemory | ( | void | ) |
bool nngn::DeviceMemory::alloc | ( | const VkMemoryRequirements * | req, |
MemoryAllocation * | alloc, | ||
VkDeviceMemory * | mem, | ||
VkDeviceSize * | offset ) |
Allocates device memory from a type that fulfills req
.
Device memory may come from a pool.
bool nngn::DeviceMemory::alloc | ( | const VkMemoryRequirements * | req, |
VkDeviceMemory * | p ) |
Allocates device memory from a type that fulfills req
.
|
private |
Shared implementation for all pooled allocations.
|
private |
Shared implementation for all dedicated allocations.
bool nngn::DeviceMemory::alloc | ( | VkBuffer | b, |
MemoryAllocation * | alloc, | ||
VkDeviceMemory * | mem, | ||
VkDeviceSize * | offset ) |
Allocates device memory from a type that fulfills req
.
Device memory may come from a pool.
bool nngn::DeviceMemory::alloc | ( | VkBuffer | buf, |
VkDeviceMemory * | p ) |
Allocates device memory from a type for a given buffer.
bool nngn::DeviceMemory::alloc | ( | VkImage | img, |
MemoryAllocation * | alloc, | ||
VkDeviceMemory * | mem, | ||
VkDeviceSize * | offset ) |
Allocates device memory from a type for a given image.
Device memory may come from a pool.
bool nngn::DeviceMemory::alloc | ( | VkImage | img, |
VkDeviceMemory * | p ) |
Allocates device memory from a type for a given image.
void nngn::DeviceMemory::dealloc | ( | MemoryAllocation | alloc | ) |
Deallocates a block of memory from an allocation pool (if necessary).
void nngn::DeviceMemory::dealloc | ( | VkDeviceMemory | mem | ) |
Deallocates a block of device memory.
find_ret< f > nngn::DeviceMemory::find_type | ( | std::uint32_t | type, |
std::uint32_t * | p ) const |
Finds a memory type among those offered by the device.
f
is required, void
. Otherwise, returns true
if a suitable type was found and written to p
. auto nngn::DeviceMemory::find_type | ( | std::uint32_t | type, |
std::uint32_t * | p ) const -> find_ret<f> |
bool nngn::DeviceMemory::init | ( | VkInstance | inst, |
VkPhysicalDevice | physical_dev, | ||
VkDevice | dev ) |
|
staticconstexpr |
Indicates whether a memory type is guaranteed to exist.
|
private |
|
private |
|
private |