5ven::Buffer::Buffer(
Device &device,
const VkDeviceSize instanceSize,
const uint32_t instanceCount,
const VkBufferUsageFlags usageFlags,
const VkMemoryPropertyFlags memoryPropertyFlags,
const VkDeviceSize minOffsetAlignment) : m_device{device}, m_instanceSize{instanceSize}, m_instanceCount{instanceCount}, m_alignmentSize(getAlignment(instanceSize, minOffsetAlignment)), m_usageFlags{usageFlags}, m_memoryPropertyFlags{memoryPropertyFlags}
14 vkDestroyBuffer(m_device.device(), m_buffer,
nullptr);
15 vkFreeMemory(m_device.device(), m_memory,
nullptr);
20 assert(m_buffer && m_memory &&
"Called map on buffer before create");
21 return vkMapMemory(m_device.device(), m_memory, offset, size, 0, &m_mapped);
26 if (m_mapped !=
nullptr) {
27 vkUnmapMemory(m_device.device(), m_memory);
34 assert(m_mapped &&
"Cannot copy to unmapped buffer");
36 if (size == VK_WHOLE_SIZE) {
37 memcpy(m_mapped, data, m_bufferSize);
39 auto *memOffset =
static_cast<char *
>(m_mapped);
41 memcpy(memOffset, data, size);
47 VkMappedMemoryRange mappedRange = {};
48 mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
49 mappedRange.memory = m_memory;
50 mappedRange.offset = offset;
51 mappedRange.size = size;
52 return vkFlushMappedMemoryRanges(m_device.device(), 1, &mappedRange);
57 VkMappedMemoryRange mappedRange = {};
58 mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
59 mappedRange.memory = m_memory;
60 mappedRange.offset = offset;
61 mappedRange.size = size;
62 return vkInvalidateMappedMemoryRanges(m_device.device(), 1, &mappedRange);
This file contains the Buffer class.
void unmap()
Unmap a mapped memory range.
VkDeviceSize m_bufferSize
VkResult map(VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0)
Map a memory range of this buffer.
VkResult flush(VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
Flush a memory range of the buffer to make it visible to the device.
VkDeviceSize m_alignmentSize
VkResult invalidate(VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
Invalidate a memory range of the buffer to make it visible to the host.
Buffer(Device &device, VkDeviceSize instanceSize, uint32_t instanceCount, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize minOffsetAlignment=1)
VkMemoryPropertyFlags m_memoryPropertyFlags
void writeToBuffer(const void *data, VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
Copies the specified data to the mapped buffer.
VkBufferUsageFlags m_usageFlags
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory) const