From 9a5112c1c9a80dc81eafbbf21aa8fa1860a87d38 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 28 Feb 2019 01:18:29 +0100 Subject: [PATCH] - tell the memory allocator when we are going to persistently map something --- src/rendering/vulkan/system/vk_buffers.cpp | 2 +- src/rendering/vulkan/system/vk_builders.h | 11 ++++++----- src/rendering/vulkan/textures/vk_hwtexture.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/rendering/vulkan/system/vk_buffers.cpp b/src/rendering/vulkan/system/vk_buffers.cpp index a255515091..7bb17f40f6 100644 --- a/src/rendering/vulkan/system/vk_buffers.cpp +++ b/src/rendering/vulkan/system/vk_buffers.cpp @@ -40,7 +40,7 @@ void VKBuffer::SetData(size_t size, const void *data, bool staticdata) else { BufferBuilder builder; - builder.setUsage(mBufferType, VMA_MEMORY_USAGE_CPU_TO_GPU); + builder.setUsage(mBufferType, VMA_MEMORY_USAGE_CPU_TO_GPU, mPersistent ? VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT : 0); builder.setSize(size); mBuffer = builder.create(fb->device); diff --git a/src/rendering/vulkan/system/vk_builders.h b/src/rendering/vulkan/system/vk_builders.h index b42a929469..bddaaacb7c 100644 --- a/src/rendering/vulkan/system/vk_builders.h +++ b/src/rendering/vulkan/system/vk_builders.h @@ -40,7 +40,7 @@ public: void setSize(int width, int height, int miplevels = 1); void setFormat(VkFormat format); - void setUsage(VkImageUsageFlags imageUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY); + void setUsage(VkImageUsageFlags imageUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY, VmaAllocationCreateFlags allocFlags = 0); void setLinearTiling(); std::unique_ptr create(VulkanDevice *device); @@ -88,7 +88,7 @@ public: BufferBuilder(); void setSize(size_t size); - void setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY); + void setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY, VmaAllocationCreateFlags allocFlags = 0); std::unique_ptr create(VulkanDevice *device); @@ -337,10 +337,11 @@ inline void ImageBuilder::setLinearTiling() imageInfo.tiling = VK_IMAGE_TILING_LINEAR; } -inline void ImageBuilder::setUsage(VkImageUsageFlags usage, VmaMemoryUsage memoryUsage) +inline void ImageBuilder::setUsage(VkImageUsageFlags usage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocFlags) { imageInfo.usage = usage; allocInfo.usage = memoryUsage; + allocInfo.flags = allocFlags; } inline std::unique_ptr ImageBuilder::create(VulkanDevice *device) @@ -469,10 +470,11 @@ inline void BufferBuilder::setSize(size_t size) bufferInfo.size = size; } -inline void BufferBuilder::setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage) +inline void BufferBuilder::setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocFlags) { bufferInfo.usage = bufferUsage; allocInfo.usage = memoryUsage; + allocInfo.flags = allocFlags; } inline std::unique_ptr BufferBuilder::create(VulkanDevice *device) @@ -480,7 +482,6 @@ inline std::unique_ptr BufferBuilder::create(VulkanDevice *device) VkBuffer buffer; VmaAllocation allocation; - allocInfo.usage = VMA_MEMORY_USAGE_CPU_TO_GPU; // we want this to be mappable. VkResult result = vmaCreateBuffer(device->allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr); if (result != VK_SUCCESS) throw std::runtime_error("could not allocate memory for vulkan buffer"); diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index a6b1df4d15..d77676c5ff 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -218,7 +218,7 @@ void VkHardwareTexture::AllocateBuffer(int w, int h, int texelsize) ImageBuilder imgbuilder; imgbuilder.setFormat(format); imgbuilder.setSize(w, h); - imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT, VMA_MEMORY_USAGE_CPU_TO_GPU); + imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT, VMA_MEMORY_USAGE_CPU_TO_GPU, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); imgbuilder.setLinearTiling(); mImage = imgbuilder.create(fb->device); mImageLayout = VK_IMAGE_LAYOUT_GENERAL;