engine backend updates to create buffer to include the vma info
This commit is contained in:
@@ -27,8 +27,8 @@ Buffer::Buffer(Device& device, vk::DeviceSize instanceSize, u32 instanceCount,
|
|||||||
memoryPropertyFlags{memoryPropertyFlags} {
|
memoryPropertyFlags{memoryPropertyFlags} {
|
||||||
alignmentSize = getAlignment(instanceSize, minOffsetAlignment);
|
alignmentSize = getAlignment(instanceSize, minOffsetAlignment);
|
||||||
bufferSize = alignmentSize * instanceCount;
|
bufferSize = alignmentSize * instanceCount;
|
||||||
device.createBuffer(bufferSize, usageFlags, memoryPropertyFlags, buffer,
|
device.createBuffer(bufferSize, this->usageFlags, this->memoryPropertyFlags,
|
||||||
allocation);
|
this->buffer, this->allocation, this->info);
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::~Buffer() {
|
Buffer::~Buffer() {
|
||||||
@@ -62,6 +62,9 @@ void Buffer::writeToBuffer(void* data, vk::DeviceSize size,
|
|||||||
if (size == VK_WHOLE_SIZE) {
|
if (size == VK_WHOLE_SIZE) {
|
||||||
memcpy(mapped, data, bufferSize);
|
memcpy(mapped, data, bufferSize);
|
||||||
} else {
|
} else {
|
||||||
|
SOPHIA_ASSERT(offset + size <= bufferSize,
|
||||||
|
"write of {} bytes at offset {} overflows buffer of {} bytes",
|
||||||
|
size, offset, bufferSize);
|
||||||
char* memOffset = (char*)mapped;
|
char* memOffset = (char*)mapped;
|
||||||
memOffset += offset;
|
memOffset += offset;
|
||||||
memcpy(memOffset, data, size);
|
memcpy(memOffset, data, size);
|
||||||
|
|||||||
@@ -36,9 +36,10 @@ class Buffer {
|
|||||||
vk::DescriptorBufferInfo descriptorInfoForIndex(int index);
|
vk::DescriptorBufferInfo descriptorInfoForIndex(int index);
|
||||||
vk::Result invalidateIndex(int index);
|
vk::Result invalidateIndex(int index);
|
||||||
|
|
||||||
vk::Buffer getBuffer() const { return buffer; }
|
void* getMappedMemory() const { return this->mapped; }
|
||||||
void* getMappedMemory() const { return mapped; }
|
vk::Buffer getBuffer() const { return this->buffer; }
|
||||||
uint32_t getInstanceCount() const { return instanceCount; }
|
const VmaAllocationInfo& getAllocationInfo() const { return this->info; }
|
||||||
|
u32 getInstanceCount() const { return instanceCount; }
|
||||||
vk::DeviceSize getInstanceSize() const { return instanceSize; }
|
vk::DeviceSize getInstanceSize() const { return instanceSize; }
|
||||||
vk::DeviceSize getAlignmentSize() const { return alignmentSize; }
|
vk::DeviceSize getAlignmentSize() const { return alignmentSize; }
|
||||||
vk::BufferUsageFlags getUsageFlags() const { return usageFlags; }
|
vk::BufferUsageFlags getUsageFlags() const { return usageFlags; }
|
||||||
@@ -55,9 +56,10 @@ class Buffer {
|
|||||||
void* mapped = nullptr;
|
void* mapped = nullptr;
|
||||||
vk::Buffer buffer = VK_NULL_HANDLE;
|
vk::Buffer buffer = VK_NULL_HANDLE;
|
||||||
VmaAllocation allocation = VK_NULL_HANDLE;
|
VmaAllocation allocation = VK_NULL_HANDLE;
|
||||||
|
VmaAllocationInfo info;
|
||||||
|
|
||||||
vk::DeviceSize bufferSize;
|
vk::DeviceSize bufferSize;
|
||||||
uint32_t instanceCount;
|
u32 instanceCount;
|
||||||
vk::DeviceSize instanceSize;
|
vk::DeviceSize instanceSize;
|
||||||
vk::DeviceSize alignmentSize;
|
vk::DeviceSize alignmentSize;
|
||||||
vk::BufferUsageFlags usageFlags;
|
vk::BufferUsageFlags usageFlags;
|
||||||
|
|||||||
@@ -184,7 +184,8 @@ vk::Format Device::findSupportedFormat(
|
|||||||
|
|
||||||
void Device::createBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage,
|
void Device::createBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage,
|
||||||
vk::MemoryPropertyFlags properties,
|
vk::MemoryPropertyFlags properties,
|
||||||
vk::Buffer& buffer, VmaAllocation& allocation) {
|
vk::Buffer& buffer, VmaAllocation& allocation,
|
||||||
|
VmaAllocationInfo& info) {
|
||||||
vk::BufferCreateInfo bufferInfo = {};
|
vk::BufferCreateInfo bufferInfo = {};
|
||||||
bufferInfo.size = size;
|
bufferInfo.size = size;
|
||||||
bufferInfo.usage = usage;
|
bufferInfo.usage = usage;
|
||||||
@@ -196,7 +197,7 @@ void Device::createBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage,
|
|||||||
VkBuffer rawBuffer = VK_NULL_HANDLE;
|
VkBuffer rawBuffer = VK_NULL_HANDLE;
|
||||||
VkResult result = vmaCreateBuffer(
|
VkResult result = vmaCreateBuffer(
|
||||||
this->allocator, &static_cast<const VkBufferCreateInfo&>(bufferInfo),
|
this->allocator, &static_cast<const VkBufferCreateInfo&>(bufferInfo),
|
||||||
&allocInfo, &rawBuffer, &allocation, nullptr);
|
&allocInfo, &rawBuffer, &allocation, &info);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
log::fatal("failed to create buffer. Error: {}",
|
log::fatal("failed to create buffer. Error: {}",
|
||||||
vk::to_string(static_cast<vk::Result>(result)));
|
vk::to_string(static_cast<vk::Result>(result)));
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class Device {
|
|||||||
|
|
||||||
void createBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage,
|
void createBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage,
|
||||||
vk::MemoryPropertyFlags properties, vk::Buffer& buffer,
|
vk::MemoryPropertyFlags properties, vk::Buffer& buffer,
|
||||||
VmaAllocation& allocation);
|
VmaAllocation& allocation, VmaAllocationInfo& info);
|
||||||
|
|
||||||
vk::CommandBuffer beginSingleTimeCommands();
|
vk::CommandBuffer beginSingleTimeCommands();
|
||||||
|
|
||||||
|
|||||||
@@ -226,11 +226,12 @@ std::unique_ptr<Image> Image::Builder::build() {
|
|||||||
|
|
||||||
vk::Buffer stagingBuffer;
|
vk::Buffer stagingBuffer;
|
||||||
VmaAllocation stagingAllocation;
|
VmaAllocation stagingAllocation;
|
||||||
this->device.createBuffer(this->initialDataSize,
|
VmaAllocationInfo stagingAllocationInfo;
|
||||||
vk::BufferUsageFlagBits::eTransferSrc,
|
this->device.createBuffer(
|
||||||
vk::MemoryPropertyFlagBits::eHostVisible |
|
this->initialDataSize, vk::BufferUsageFlagBits::eTransferSrc,
|
||||||
vk::MemoryPropertyFlagBits::eHostCoherent,
|
vk::MemoryPropertyFlagBits::eHostVisible |
|
||||||
stagingBuffer, stagingAllocation);
|
vk::MemoryPropertyFlagBits::eHostCoherent,
|
||||||
|
stagingBuffer, stagingAllocation, stagingAllocationInfo);
|
||||||
|
|
||||||
void* mapped = nullptr;
|
void* mapped = nullptr;
|
||||||
vmaMapMemory(allocator, stagingAllocation, &mapped);
|
vmaMapMemory(allocator, stagingAllocation, &mapped);
|
||||||
|
|||||||
Reference in New Issue
Block a user