Fixing VMA improper destruction

This commit is contained in:
Dynamitos
2024-01-17 19:34:38 +01:00
parent 524f26d921
commit 00672cf08e
8 changed files with 41 additions and 23 deletions
+2 -2
View File
@@ -50,7 +50,7 @@ Buffer::~Buffer()
{
for (uint32 i = 0; i < numBuffers; ++i)
{
graphics->getDestructionManager()->queueBuffer(graphics->getQueueCommands(owner)->getCommands(), buffers[i].buffer);
graphics->getDestructionManager()->queueBuffer(graphics->getQueueCommands(owner)->getCommands(), buffers[i].buffer, buffers[i].allocation);
}
}
@@ -241,7 +241,7 @@ void Buffer::unmap()
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
vmaDestroyBuffer(graphics->getAllocator(), pending.stagingBuffer, pending.allocation);
graphics->getDestructionManager()->queueBuffer(command, pending.stagingBuffer, pending.allocation);
}
}
// requestOwnershipTransfer(pending.prevQueue);
+8 -8
View File
@@ -99,14 +99,14 @@ DestructionManager::~DestructionManager()
{
}
void DestructionManager::queueBuffer(PCommand cmd, VkBuffer buffer)
void DestructionManager::queueBuffer(PCommand cmd, VkBuffer buffer, VmaAllocation alloc)
{
buffers[cmd].add(buffer);
buffers[cmd].add({buffer, alloc});
}
void DestructionManager::queueImage(PCommand cmd, VkImage image)
void DestructionManager::queueImage(PCommand cmd, VkImage image, VmaAllocation alloc)
{
images[cmd].add(image);
images[cmd].add({image, alloc});
}
void DestructionManager::queueImageView(PCommand cmd, VkImageView image)
@@ -131,17 +131,17 @@ void DestructionManager::queueDescriptorPool(PCommand cmd, VkDescriptorPool pool
void DestructionManager::notifyCmdComplete(PCommand cmd)
{
for(auto buf : buffers[cmd])
for(auto [buf, alloc] : buffers[cmd])
{
vkDestroyBuffer(graphics->getDevice(), buf, nullptr);
vmaDestroyBuffer(graphics->getAllocator(), buf, alloc);
}
for(auto view : views[cmd])
{
vkDestroyImageView(graphics->getDevice(), view, nullptr);
}
for(auto img : images[cmd])
for(auto [img, alloc] : images[cmd])
{
vkDestroyImage(graphics->getDevice(), img, nullptr);
vmaDestroyImage(graphics->getAllocator(), img, alloc);
}
for (auto sem : sems[cmd])
{
+5 -5
View File
@@ -1,8 +1,8 @@
#pragma once
#include <vulkan/vulkan.h>
#include <vk_mem_alloc.h>
#include "Containers/List.h"
#include "Graphics/Resources.h"
#include "Allocator.h"
namespace Seele
{
@@ -56,8 +56,8 @@ class DestructionManager
public:
DestructionManager(PGraphics graphics);
~DestructionManager();
void queueBuffer(PCommand cmd, VkBuffer buffer);
void queueImage(PCommand cmd, VkImage image);
void queueBuffer(PCommand cmd, VkBuffer buffer, VmaAllocation alloc);
void queueImage(PCommand cmd, VkImage image, VmaAllocation alloc);
void queueImageView(PCommand cmd, VkImageView view);
void queueSemaphore(PCommand cmd, VkSemaphore sem);
void queueRenderPass(PCommand cmd, VkRenderPass renderPass);
@@ -65,8 +65,8 @@ public:
void notifyCmdComplete(PCommand cmdbuffer);
private:
PGraphics graphics;
Map<PCommand, List<VkBuffer>> buffers;
Map<PCommand, List<VkImage>> images;
Map<PCommand, List<Pair<VkBuffer, VmaAllocation>>> buffers;
Map<PCommand, List<Pair<VkImage, VmaAllocation>>> images;
Map<PCommand, List<VkImageView>> views;
Map<PCommand, List<VkSemaphore>> sems;
Map<PCommand, List<VkRenderPass>> renderPasses;
+5 -3
View File
@@ -126,6 +126,7 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
};
VmaAllocationCreateInfo alloc = {
.usage = VMA_MEMORY_USAGE_AUTO,
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
};
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &alloc, &stagingBuffer, &stagingAlloc, nullptr));
vmaMapMemory(graphics->getAllocator(), stagingAlloc, &data);
@@ -163,7 +164,8 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
if(stagingBuffer != VK_NULL_HANDLE)
{
vmaDestroyBuffer(graphics->getAllocator(), stagingBuffer, stagingAlloc);
vmaUnmapMemory(graphics->getAllocator(), stagingAlloc);
graphics->getDestructionManager()->queueBuffer(commandPool->getCommands(), stagingBuffer, stagingAlloc);
}
}
}
@@ -202,7 +204,7 @@ TextureBase::~TextureBase()
{
if (ownsImage)
{
graphics->getDestructionManager()->queueImage(graphics->getQueueCommands(currentOwner)->getCommands(), image);
graphics->getDestructionManager()->queueImage(graphics->getQueueCommands(currentOwner)->getCommands(), image, allocation);
}
graphics->getDestructionManager()->queueImageView(graphics->getQueueCommands(currentOwner)->getCommands(), imageView);
}
@@ -251,7 +253,7 @@ void TextureBase::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Arra
.pNext = nullptr,
.flags = 0,
.size = imageSize,
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
VmaAllocationCreateInfo alloc = {