diff --git a/src/rendering/vulkan/system/vk_buffers.cpp b/src/rendering/vulkan/system/vk_buffers.cpp index 7cce200c7..1dd36f970 100644 --- a/src/rendering/vulkan/system/vk_buffers.cpp +++ b/src/rendering/vulkan/system/vk_buffers.cpp @@ -6,9 +6,22 @@ #include "vulkan/renderer/vk_renderpass.h" #include "doomerrors.h" +VKBuffer *VKBuffer::First = nullptr; + +VKBuffer::VKBuffer() +{ + Next = First; + First = this; + if (Next) Next->Prev = this; +} + VKBuffer::~VKBuffer() { - if (map) + if (Next) Next->Prev = Prev; + if (Prev) Prev->Next = Next; + else First = Next; + + if (mBuffer && map) mBuffer->Unmap(); auto fb = GetVulkanFrameBuffer(); @@ -16,6 +29,14 @@ VKBuffer::~VKBuffer() fb->FrameDeleteList.Buffers.push_back(std::move(mBuffer)); } +void VKBuffer::Reset() +{ + if (mBuffer && map) + mBuffer->Unmap(); + mBuffer.reset(); + mStaging.reset(); +} + void VKBuffer::SetData(size_t size, const void *data, bool staticdata) { auto fb = GetVulkanFrameBuffer(); diff --git a/src/rendering/vulkan/system/vk_buffers.h b/src/rendering/vulkan/system/vk_buffers.h index 0477f1b68..df99cf1c0 100644 --- a/src/rendering/vulkan/system/vk_buffers.h +++ b/src/rendering/vulkan/system/vk_buffers.h @@ -13,8 +13,11 @@ class VKBuffer : virtual public IBuffer { public: + VKBuffer(); ~VKBuffer(); + void Reset(); + void SetData(size_t size, const void *data, bool staticdata) override; void SetSubData(size_t offset, size_t size, const void *data) override; void Resize(size_t newsize) override; @@ -25,6 +28,10 @@ public: void *Lock(unsigned int size) override; void Unlock() override; + static VKBuffer *First; + VKBuffer *Prev = nullptr; + VKBuffer *Next = nullptr; + VkBufferUsageFlags mBufferType = 0; std::unique_ptr mBuffer; std::unique_ptr mStaging; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 91878795c..d664204f9 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -89,6 +89,9 @@ VulkanFrameBuffer::~VulkanFrameBuffer() for (VkHardwareTexture *cur = VkHardwareTexture::First; cur; cur = cur->Next) cur->Reset(); + for (VKBuffer *cur = VKBuffer::First; cur; cur = cur->Next) + cur->Reset(); + PPResource::ResetAll(); delete MatricesUBO;