nngn
Loading...
Searching...
No Matches
nngn::DeviceMemory Class Reference

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< ffind_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 = {}
 

Detailed Description

Manages device memory queries, allocations, and lifetime.

Member Typedef Documentation

◆ find_ret

template<VkMemoryPropertyFlags f>
using nngn::DeviceMemory::find_ret = std::conditional_t<required(f), void, bool>

Constructor & Destructor Documentation

◆ DeviceMemory()

nngn::DeviceMemory::DeviceMemory ( void )
default

◆ ~DeviceMemory()

nngn::DeviceMemory::~DeviceMemory ( void )

Member Function Documentation

◆ alloc() [1/8]

template<VkMemoryPropertyFlags f>
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.

Here is the call graph for this function:

◆ alloc() [2/8]

template<VkMemoryPropertyFlags f>
bool nngn::DeviceMemory::alloc ( const VkMemoryRequirements * req,
VkDeviceMemory * p )

Allocates device memory from a type that fulfills req.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ alloc() [3/8]

bool nngn::DeviceMemory::alloc ( std::uint32_t type,
const VkMemoryRequirements * req,
MemoryAllocation * alloc,
VkDeviceMemory * mem,
VkDeviceSize * offset )
private

Shared implementation for all pooled allocations.

Here is the call graph for this function:

◆ alloc() [4/8]

bool nngn::DeviceMemory::alloc ( std::uint32_t type,
VkDeviceSize size,
VkDeviceMemory * p )
private

Shared implementation for all dedicated allocations.

Here is the call graph for this function:

◆ alloc() [5/8]

template<VkMemoryPropertyFlags f>
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.

Here is the call graph for this function:

◆ alloc() [6/8]

template<VkMemoryPropertyFlags f>
bool nngn::DeviceMemory::alloc ( VkBuffer buf,
VkDeviceMemory * p )

Allocates device memory from a type for a given buffer.

Here is the call graph for this function:

◆ alloc() [7/8]

template<VkMemoryPropertyFlags f>
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.

Here is the call graph for this function:

◆ alloc() [8/8]

template<VkMemoryPropertyFlags f>
bool nngn::DeviceMemory::alloc ( VkImage img,
VkDeviceMemory * p )

Allocates device memory from a type for a given image.

Here is the call graph for this function:

◆ dealloc() [1/2]

void nngn::DeviceMemory::dealloc ( MemoryAllocation alloc)

Deallocates a block of memory from an allocation pool (if necessary).

Here is the call graph for this function:

◆ dealloc() [2/2]

void nngn::DeviceMemory::dealloc ( VkDeviceMemory mem)

Deallocates a block of device memory.

Here is the caller graph for this function:

◆ find_type() [1/2]

template<VkMemoryPropertyFlags f>
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.

Returns
If f is required, void. Otherwise, returns true if a suitable type was found and written to p.
Here is the caller graph for this function:

◆ find_type() [2/2]

template<VkMemoryPropertyFlags f>
auto nngn::DeviceMemory::find_type ( std::uint32_t type,
std::uint32_t * p ) const -> find_ret<f>
Here is the call graph for this function:

◆ init()

bool nngn::DeviceMemory::init ( VkInstance inst,
VkPhysicalDevice physical_dev,
VkDevice dev )
Here is the caller graph for this function:

◆ required()

bool nngn::DeviceMemory::required ( VkMemoryPropertyFlags f)
staticconstexpr

Indicates whether a memory type is guaranteed to exist.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ allocator

void* nngn::DeviceMemory::allocator = {}
private

◆ dev

VkDevice nngn::DeviceMemory::dev = {}
private

◆ props

VkPhysicalDeviceMemoryProperties nngn::DeviceMemory::props = {}
private

The documentation for this class was generated from the following files: