1#ifndef NNGN_GRAPHICS_VULKAN_MEMORY_H
2#define NNGN_GRAPHICS_VULKAN_MEMORY_H
23 static constexpr bool required(VkMemoryPropertyFlags
f);
24 template<VkMemoryPropertyFlags f>
29 bool init(VkInstance inst, VkPhysicalDevice physical_dev, VkDevice
dev);
36 template<VkMemoryPropertyFlags
f>
39 template<VkMemoryPropertyFlags
f>
40 bool alloc(
const VkMemoryRequirements *req, VkDeviceMemory *p);
45 template<VkMemoryPropertyFlags
f>
48 VkDeviceMemory *mem, VkDeviceSize *offset);
50 template<VkMemoryPropertyFlags
f>
51 bool alloc(VkBuffer buf, VkDeviceMemory *p);
56 template<VkMemoryPropertyFlags
f>
59 VkDeviceMemory *mem, VkDeviceSize *offset);
61 template<VkMemoryPropertyFlags
f>
67 template<VkMemoryPropertyFlags
f>
70 VkDeviceMemory *mem, VkDeviceSize *offset);
72 void dealloc(VkDeviceMemory mem);
77 bool alloc(
std::uint32_t type, VkDeviceSize size, VkDeviceMemory *p);
80 std::uint32_t type,
const VkMemoryRequirements *req,
84 VkPhysicalDeviceMemoryProperties
props = {};
89 std::vector<Graphics::MemoryHeap>
heaps = {};
91 void init(VkPhysicalDevice dev);
95 constexpr auto device = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
96 constexpr auto host = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
97 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
98 return f & device || (
f & host) == host;
101template<VkMemoryPropertyFlags f>
103 std::uint32_t type, std::uint32_t *p
105 constexpr auto ret = []([[maybe_unused]]
auto b) {
109 for(std::uint32_t
i = 0;
i < this->props.memoryTypeCount; ++
i) {
110 if(!(type & (std::uint32_t{1} <<
i)))
112 if((this->props.memoryTypes[
i].propertyFlags &
f) !=
f)
118 Log::l() <<
"no suitable type found\n";
122template<VkMemoryPropertyFlags f>
124 const VkMemoryRequirements *req, VkDeviceMemory *p
126 std::uint32_t type = {};
129 else if(!this->
find_type<f>(req->memoryTypeBits, &type))
131 return this->
alloc(type, req->size, p);
134template<VkMemoryPropertyFlags f>
137 VkDeviceMemory *mem, VkDeviceSize *offset
139 std::uint32_t type = {};
142 else if(!this->
find_type<f>(req->memoryTypeBits, &type))
144 return this->
alloc(type, req,
alloc, mem, offset);
147template<VkMemoryPropertyFlags f>
149 VkMemoryRequirements req;
150 vkGetBufferMemoryRequirements(this->
dev, b, &req);
154template<VkMemoryPropertyFlags f>
157 VkDeviceMemory *mem, VkDeviceSize *offset
159 VkMemoryRequirements req;
160 vkGetBufferMemoryRequirements(this->
dev, b, &req);
164template<VkMemoryPropertyFlags f>
166 VkMemoryRequirements req;
167 vkGetImageMemoryRequirements(this->
dev, img, &req);
171template<VkMemoryPropertyFlags f>
174 VkDeviceMemory *mem, VkDeviceSize *offset
176 VkMemoryRequirements req;
177 vkGetImageMemoryRequirements(this->
dev, img, &req);
local class const
Definition animation.lua:7
Manages device memory queries, allocations, and lifetime.
Definition memory.h:20
void dealloc(VkDeviceMemory mem)
Deallocates a block of device memory.
Definition memory.cpp:155
static constexpr bool required(VkMemoryPropertyFlags f)
Indicates whether a memory type is guaranteed to exist.
Definition memory.h:94
bool alloc(const VkMemoryRequirements *req, VkDeviceMemory *p)
Allocates device memory from a type that fulfills req.
Definition memory.h:123
std::conditional_t< required(f), void, bool > find_ret
Definition memory.h:25
void * allocator
Definition memory.h:83
VkDevice dev
Definition memory.h:82
VkPhysicalDeviceMemoryProperties props
Definition memory.h:84
find_ret< f > find_type(std::uint32_t type, std::uint32_t *p) const
Finds a memory type among those offered by the device.
static std::ostream & l()
Definition log.cpp:56
for i
Definition font.lua:5
init
Definition img_common.lua:34
local img
Definition img_conv.lua:27
#define NNGN_LOG_CONTEXT_CF(c)
Definition log.h:11
std::uint64_t MemoryAllocation
Definition memory.h:17
COMMAND_BUFFER DESCRIPTOR_POOL DESCRIPTOR_SET_LAYOUT FENCE VkImage
Definition types.h:72
#define NNGN_MOVE_ONLY(x)
Definition utils.h:39
Aggregate type for information about a device's memory heaps.
Definition memory.h:88
std::vector< Graphics::MemoryHeap > heaps
Definition memory.h:89
std::vector< std::vector< Graphics::MemoryType > > memory_types
Definition memory.h:90