From d985d981228c11858d1133832f17c33e52b2c52a Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 30 Apr 2019 19:36:34 +0200 Subject: [PATCH] - release staging buffer after the frame it was used in --- src/rendering/vulkan/textures/vk_hwtexture.cpp | 13 +++++++------ src/rendering/vulkan/textures/vk_hwtexture.h | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index 8c0af229d..3964235d2 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -65,7 +65,6 @@ void VkHardwareTexture::Reset() auto &deleteList = fb->FrameDeleteList; if (mImage) deleteList.Images.push_back(std::move(mImage)); if (mImageView) deleteList.ImageViews.push_back(std::move(mImageView)); - if (mStagingBuffer) deleteList.Buffers.push_back(std::move(mStagingBuffer)); } } @@ -223,12 +222,12 @@ void VkHardwareTexture::CreateTexture(int w, int h, int pixelsize, VkFormat form BufferBuilder bufbuilder; bufbuilder.setSize(totalSize); bufbuilder.setUsage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY); - mStagingBuffer = bufbuilder.create(fb->device); - mStagingBuffer->SetDebugName("VkHardwareTexture.mStagingBuffer"); + std::unique_ptr stagingBuffer = bufbuilder.create(fb->device); + stagingBuffer->SetDebugName("VkHardwareTexture.mStagingBuffer"); - uint8_t *data = (uint8_t*)mStagingBuffer->Map(0, totalSize); + uint8_t *data = (uint8_t*)stagingBuffer->Map(0, totalSize); memcpy(data, pixels, totalSize); - mStagingBuffer->Unmap(); + stagingBuffer->Unmap(); ImageBuilder imgbuilder; imgbuilder.setFormat(format); @@ -254,7 +253,9 @@ void VkHardwareTexture::CreateTexture(int w, int h, int pixelsize, VkFormat form region.imageExtent.depth = 1; region.imageExtent.width = w; region.imageExtent.height = h; - cmdbuffer->copyBufferToImage(mStagingBuffer->buffer, mImage->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + cmdbuffer->copyBufferToImage(stagingBuffer->buffer, mImage->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + + fb->FrameDeleteList.Buffers.push_back(std::move(stagingBuffer)); GenerateMipmaps(mImage.get(), cmdbuffer); } diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/rendering/vulkan/textures/vk_hwtexture.h index 0334bbbda..78524b103 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/rendering/vulkan/textures/vk_hwtexture.h @@ -72,7 +72,6 @@ private: std::vector mDescriptorSets; std::unique_ptr mImage; std::unique_ptr mImageView; - std::unique_ptr mStagingBuffer; VkImageLayout mImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; int mTexelsize = 4; };