1#ifndef NNGN_GRAPHICS_VULKAN_STAGING_H
2#define NNGN_GRAPHICS_VULKAN_STAGING_H
46 bool write(
std::
size_t i, VkDeviceSize
n, VkDeviceSize size, auto &&
f);
56 std::vector<DedicatedBuffer>
blocks = {};
68 VkDeviceMemory
mem = {};
71 const DedicatedBuffer *
cur_block(std::size_t
i)
const;
84 Allocation
alloc(std::size_t
i, VkDeviceSize
n, VkDeviceSize size);
91 MappedRegion
map(std::size_t
i, VkDeviceSize
n, VkDeviceSize size);
100 std::vector<FreeBuffer>
free = {};
109 VkDeviceSize default_size_
118 for(std::size_t
i =
n, old = this->
frames.size();
i < old; ++
i)
128 return f.blocks.empty() ? nullptr : &
f.blocks.back();
137 std::size_t
i, VkDeviceSize
n, VkDeviceSize size,
auto &&
f
140 for(std::size_t bi = 0;
n;) {
141 auto [mem, off, nw] = this->
map(i,
n, size);
144 void *
const p =
static_cast<char*
>(this->
frames[
i].mapped) + off;
145 if(!
f(this->
cur_block(i)->
id(), p, off, bi, nw))
147 bi +=
static_cast<std::size_t
>(nw);
148 n -=
static_cast<std::size_t
>(nw);
local class const
Definition animation.lua:7
Manages device memory queries, allocations, and lifetime.
Definition memory.h:20
Owning wrapper for a Vulkan instance.
Definition instance.h:19
Manages staging buffers for a group of frames.
Definition staging.h:20
const DedicatedBuffer * cur_block(std::size_t i) const
Definition staging.h:123
VkDeviceSize default_size
Definition staging.h:104
void destroy(std::size_t i)
Releases resources for frame i.
Definition staging.cpp:42
std::vector< Frame > frames
Definition staging.h:99
Allocation alloc(std::size_t i, VkDeviceSize n, VkDeviceSize size)
Allocates at most n blocks of size bytes for frame i.
Definition staging.cpp:78
void resize(std::size_t n)
Resizes to accommodate n frames.
Definition staging.h:117
VkDevice dev
Definition staging.h:102
const Instance * inst
Definition staging.h:101
bool write(std::size_t i, VkDeviceSize n, VkDeviceSize size, auto &&f)
Writes data for a frame, allocating extra memory as necessary.
Definition staging.h:136
DeviceMemory * dev_mem
Definition staging.h:103
void retire_free()
Removes old unused buffers from the free list.
Definition staging.cpp:48
std::vector< FreeBuffer > free
Definition staging.h:100
void init(const Instance &inst, VkDevice dev, DeviceMemory *dev_mem, VkDeviceSize default_size)
Definition staging.h:107
assert
Definition debug.lua:3
local map
Definition demo1.lua:4
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
init
Definition img_common.lua:34
#define NNGN_LOG_CONTEXT_CF(c)
Definition log.h:11
std::uint32_t u32
Definition def.h:14
std::uint8_t u8
Definition def.h:12
std::uint64_t u64
Definition def.h:15
#define NNGN_MOVE_ONLY(x)
Definition utils.h:39
Result of a block allocation.
Definition staging.h:62
DedicatedBuffer * block
Definition staging.h:63
VkDeviceSize n
Definition staging.h:64
VkDeviceSize offset
Definition staging.h:64
Data for a single frame.
Definition staging.h:53
u32 n_reused
Definition staging.h:58
u32 n_alloc
Definition staging.h:58
std::vector< DedicatedBuffer > blocks
Definition staging.h:56
void destroy(VkDevice dev, DeviceMemory *dev_mem)
Definition staging.cpp:26
u32 n_req_alloc
Definition staging.h:58
void * mapped
Definition staging.h:57
u64 req_mem
Definition staging.h:59
Buffer in the free list, ready to be reused.
Definition staging.h:51
Region mapped for writting.
Definition staging.h:67
VkDeviceSize n
Definition staging.h:69
VkDeviceMemory mem
Definition staging.h:68
VkDeviceSize offset
Definition staging.h:69
local stats
Definition timeline.lua:5