1#ifndef NNGN_GRAPHICS_VULKAN_STAGING_H
2#define NNGN_GRAPHICS_VULKAN_STAGING_H
6#include "graphics/stats.h"
46 bool write(
std::
size_t i, VkDeviceSize
n, VkDeviceSize size, auto &&
f);
56 std::vector<DedicatedBuffer>
blocks = {};
63 DedicatedBuffer *
block = {};
64 VkDeviceSize
offset = {},
n = {};
69 VkDeviceSize
offset = {},
n = {};
99 std::vector<Frame>
frames = {};
100 std::vector<FreeBuffer>
free = {};
101 const Instance *
inst = {};
108 const Instance &inst_, VkDevice dev_, DeviceMemory *dev_mem_,
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();
132 return const_cast<DedicatedBuffer*
>(
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;
147 bi +=
static_cast<std::size_t
>(nw);
148 n -=
static_cast<std::size_t
>(nw);
Definition: resource.h:41
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
std::vector< FreeBuffer > free
Definition: staging.h:100
const DedicatedBuffer * cur_block(std::size_t i) const
MappedRegion map(std::size_t i, VkDeviceSize n, VkDeviceSize size)
Maps a writeable region, allocating if necessary.
std::vector< Frame > frames
Definition: staging.h:99
VkDeviceSize default_size
Definition: staging.h:104
void destroy(std::size_t i)
Releases resources for frame i.
Definition: staging.cpp:42
DeviceMemory * dev_mem
Definition: staging.h:103
DedicatedBuffer * cur_block(std::size_t i)
void resize(std::size_t n)
Resizes to accommodate n frames.
Definition: staging.h:117
VkDevice dev
Definition: staging.h:102
Allocation alloc(std::size_t i, VkDeviceSize n, VkDeviceSize size)
Allocates at most n blocks of size bytes for frame i.
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
void retire_free()
Removes old unused buffers from the free list.
StagingBuffer(void)=default
void init(const Instance &inst, VkDevice dev, DeviceMemory *dev_mem, VkDeviceSize default_size)
Definition: staging.h:107
init
Definition: img_common.lua:34
map
Definition: demo1.lua:4
for i
Definition: font.lua:5
assert
Definition: debug.lua:3
n
Definition: dump_lights.lua:5
stats
Definition: timeline.lua:5
#define NNGN_LOG_CONTEXT_CF(c)
Definition: log.h:11
#define NNGN_MOVE_ONLY(x)
Definition: utils.h:39
std::uint32_t u32
Definition: def.h:14
COMMAND_BUFFER DESCRIPTOR_POOL DESCRIPTOR_SET_LAYOUT FENCE IMAGE PIPELINE PIPELINE_CACHE RENDER_PASS SEMAPHORE BUFFER COMMAND_POOL DESCRIPTOR_SET VkDeviceMemory
Definition: types.h:77
std::uint64_t u64
Definition: def.h:15
std::uint8_t u8
Definition: def.h:12
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
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)
u32 n_req_alloc
Definition: staging.h:58
void release(VkDevice dev, std::vector< FreeBuffer > *free)
u64 req_mem
Definition: staging.h:59
void * mapped
Definition: staging.h:57
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