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