7 if (minOffsetAlignment > 0) {
8 return (instanceSize + minOffsetAlignment - 1) & ~(minOffsetAlignment - 1);
13ven::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}
22 vkDestroyBuffer(m_device.device(), m_buffer,
nullptr);
23 vkFreeMemory(m_device.device(), m_memory,
nullptr);
28 assert(m_buffer && m_memory &&
"Called map on m_buffer before create");
29 return vkMapMemory(m_device.device(), m_memory, offset, size, 0, &m_mapped);
34 if (m_mapped !=
nullptr) {
35 vkUnmapMemory(m_device.device(), m_memory);
42 assert(m_mapped &&
"Cannot copy to unmapped m_buffer");
44 if (size == VK_WHOLE_SIZE) {
45 memcpy(m_mapped, data, m_bufferSize);
47 char *memOffset =
static_cast<char *
>(m_mapped);
49 memcpy(memOffset, data, size);
55 VkMappedMemoryRange mappedRange = {};
56 mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
57 mappedRange.memory = m_memory;
58 mappedRange.offset = offset;
59 mappedRange.size = size;
60 return vkFlushMappedMemoryRanges(m_device.device(), 1, &mappedRange);
65 VkMappedMemoryRange mappedRange = {};
66 mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
67 mappedRange.memory = m_memory;
68 mappedRange.offset = offset;
69 mappedRange.size = size;
70 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.
static VkDeviceSize getAlignment(VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment)
Returns the minimum instance size required to be compatible with devices minOffsetAlignment.
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 propertiesp, VkBuffer &buffer, VkDeviceMemory &bufferMemory) const