Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/drape
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2019-02-19 14:40:20 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2019-03-01 10:45:24 +0300
commitd4dd122572599524f5841c04edb5c9de0d14ba7b (patch)
tree285e6f9821775581742f1b06dd8d79e59de255f7 /drape
parent55586aab65ec7d2630ed9a6f251872b1fe77863b (diff)
[vulkan] Fixed memory manager
Diffstat (limited to 'drape')
-rw-r--r--drape/vulkan/vulkan_base_context.cpp14
-rw-r--r--drape/vulkan/vulkan_gpu_buffer_impl.cpp2
-rw-r--r--drape/vulkan/vulkan_memory_manager.cpp80
-rw-r--r--drape/vulkan/vulkan_object_manager.cpp33
-rw-r--r--drape/vulkan/vulkan_object_manager.hpp1
-rw-r--r--drape/vulkan/vulkan_pipeline.cpp2
-rw-r--r--drape/vulkan/vulkan_texture.cpp2
7 files changed, 81 insertions, 53 deletions
diff --git a/drape/vulkan/vulkan_base_context.cpp b/drape/vulkan/vulkan_base_context.cpp
index 8a328490a6..8e929c014e 100644
--- a/drape/vulkan/vulkan_base_context.cpp
+++ b/drape/vulkan/vulkan_base_context.cpp
@@ -1,4 +1,6 @@
#include "drape/vulkan/vulkan_base_context.hpp"
+
+#include "drape/drape_routine.hpp"
#include "drape/vulkan/vulkan_staging_buffer.hpp"
#include "drape/vulkan/vulkan_texture.hpp"
#include "drape/vulkan/vulkan_utils.hpp"
@@ -509,7 +511,17 @@ void VulkanBaseContext::Present()
// Resetting of the default staging buffer and collecting destroyed objects must be
// only after the finishing of rendering. It prevents data collisions.
m_defaultStagingBuffer->Reset();
- m_objectManager->CollectObjects();
+
+ static uint8_t framesCounter = 0;
+ if (framesCounter % 10 == 0)
+ {
+ framesCounter = 0;
+ DrapeRoutine::Run([this]() { m_objectManager->CollectObjects(); });
+ }
+ else
+ {
+ framesCounter++;
+ }
m_pipelineKey = {};
m_stencilReferenceValue = 1;
diff --git a/drape/vulkan/vulkan_gpu_buffer_impl.cpp b/drape/vulkan/vulkan_gpu_buffer_impl.cpp
index a12feab946..8f66c1ffbe 100644
--- a/drape/vulkan/vulkan_gpu_buffer_impl.cpp
+++ b/drape/vulkan/vulkan_gpu_buffer_impl.cpp
@@ -120,7 +120,7 @@ void VulkanGPUBuffer::Resize(ref_ptr<VulkanBaseContext> context, void const * da
uint32_t const sizeInBytes = GetCapacity() * GetElementSize();
m_geometryBuffer = m_objectManager->CreateBuffer(VulkanMemoryManager::ResourceType::Geometry,
- sizeInBytes, 0 /* batcherHash */);
+ sizeInBytes, m_batcherHash);
m_objectManager->Fill(m_geometryBuffer, data, sizeInBytes);
// If we have already set up data, we have to call SetDataSize.
diff --git a/drape/vulkan/vulkan_memory_manager.cpp b/drape/vulkan/vulkan_memory_manager.cpp
index 15f8e2a248..08cb4a56d3 100644
--- a/drape/vulkan/vulkan_memory_manager.cpp
+++ b/drape/vulkan/vulkan_memory_manager.cpp
@@ -15,20 +15,20 @@ namespace vulkan
namespace
{
std::array<uint32_t, VulkanMemoryManager::kResourcesCount> const kMinBlockSizeInBytes =
-{
- 64 * 1024, // Geometry
- 0, // Uniform (no minimal size)
- 0, // Staging (no minimal size)
- 0, // Image (no minimal size)
-};
+{{
+ 1024 * 1024, // Geometry
+ 0, // Uniform (no minimal size)
+ 0, // Staging (no minimal size)
+ 0, // Image (no minimal size)
+}};
std::array<uint32_t, VulkanMemoryManager::kResourcesCount> const kDesiredSizeInBytes =
-{
+{{
80 * 1024 * 1024, // Geometry
std::numeric_limits<uint32_t>::max(), // Uniform (unlimited)
20 * 1024 * 1024, // Staging
std::numeric_limits<uint32_t>::max(), // Image (unlimited)
-};
+}};
VkMemoryPropertyFlags GetMemoryPropertyFlags(VulkanMemoryManager::ResourceType resourceType,
boost::optional<VkMemoryPropertyFlags> & fallbackTypeBits)
@@ -175,6 +175,7 @@ VulkanMemoryManager::AllocationPtr VulkanMemoryManager::Allocate(ResourceType re
freeBlock->m_allocationCounter++;
auto p = std::make_shared<Allocation>(resourceType, blockHash, 0, alignedSize,
make_ref(freeBlock));
+
m[blockHash].push_back(std::move(freeBlock));
return p;
}
@@ -231,8 +232,8 @@ void VulkanMemoryManager::Deallocate(AllocationPtr ptr)
{
CHECK(ptr, ());
CHECK(!ptr->m_memoryBlock->m_isBlocked, ());
- auto const kResourceIndex = static_cast<size_t>(ptr->m_resourceType);
- auto & m = m_memory[kResourceIndex];
+ auto const resourceIndex = static_cast<size_t>(ptr->m_resourceType);
+ auto & m = m_memory[resourceIndex];
auto const it = m.find(ptr->m_blockHash);
CHECK(it != m.end(), ());
auto blockIt = std::find_if(it->second.begin(), it->second.end(),
@@ -251,22 +252,22 @@ void VulkanMemoryManager::Deallocate(AllocationPtr ptr)
{
// Here we set a bit in the deallocation mask to skip the processing of untouched
// resource collections.
- m_deallocationSessionMask |= (1 << kResourceIndex);
+ m_deallocationSessionMask |= (1 << resourceIndex);
}
else
{
drape_ptr<MemoryBlock> memoryBlock = std::move(*blockIt);
it->second.erase(blockIt);
- if (m_sizes[kResourceIndex] > kDesiredSizeInBytes[kResourceIndex])
+ if (m_sizes[resourceIndex] > kDesiredSizeInBytes[resourceIndex])
{
- CHECK_LESS_OR_EQUAL(memoryBlock->m_blockSize, m_sizes[kResourceIndex], ());
- m_sizes[kResourceIndex] -= memoryBlock->m_blockSize;
+ CHECK_LESS_OR_EQUAL(memoryBlock->m_blockSize, m_sizes[resourceIndex], ());
+ m_sizes[resourceIndex] -= memoryBlock->m_blockSize;
vkFreeMemory(m_device, memoryBlock->m_memory, nullptr);
}
else
{
memoryBlock->m_freeOffset = 0;
- auto & fm = m_freeBlocks[kResourceIndex];
+ auto & fm = m_freeBlocks[resourceIndex];
fm.push_back(std::move(memoryBlock));
std::sort(fm.begin(), fm.end(), &Less);
}
@@ -287,28 +288,41 @@ void VulkanMemoryManager::EndDeallocationSession()
continue;
auto & fm = m_freeBlocks[i];
- auto & m = m_memory[i];
- m[i].erase(std::remove_if(m[i].begin(), m[i].end(),
- [this, &fm, i](drape_ptr<MemoryBlock> & b)
+
+ static std::vector<uint64_t> hashesToDelete;
+ for (auto & p : m_memory[i])
{
- if (b->m_allocationCounter == 0)
+ auto & m = p.second;
+ m.erase(std::remove_if(m.begin(), m.end(),
+ [this, &fm, i](drape_ptr<MemoryBlock> & b)
{
- if (m_sizes[i] > kDesiredSizeInBytes[i])
- {
- CHECK_LESS_OR_EQUAL(b->m_blockSize, m_sizes[i], ());
- m_sizes[i] -= b->m_blockSize;
- vkFreeMemory(m_device, b->m_memory, nullptr);
- }
- else
+ if (b->m_allocationCounter == 0)
{
- auto block = std::move(b);
- block->m_freeOffset = 0;
- fm.push_back(std::move(block));
+ if (m_sizes[i] > kDesiredSizeInBytes[i])
+ {
+ CHECK_LESS_OR_EQUAL(b->m_blockSize, m_sizes[i], ());
+ m_sizes[i] -= b->m_blockSize;
+ vkFreeMemory(m_device, b->m_memory, nullptr);
+ }
+ else
+ {
+ auto block = std::move(b);
+ block->m_freeOffset = 0;
+ fm.push_back(std::move(block));
+ }
+ return true;
}
- return true;
- }
- return false;
- }), m[i].end());
+ return false;
+ }), m.end());
+
+ if (m.empty())
+ hashesToDelete.push_back(p.first);
+ }
+
+ for (auto hash : hashesToDelete)
+ m_memory[i].erase(hash);
+ hashesToDelete.clear();
+
std::sort(fm.begin(), fm.end(), &Less);
}
}
diff --git a/drape/vulkan/vulkan_object_manager.cpp b/drape/vulkan/vulkan_object_manager.cpp
index d43d2bff3f..1a5247baf7 100644
--- a/drape/vulkan/vulkan_object_manager.cpp
+++ b/drape/vulkan/vulkan_object_manager.cpp
@@ -58,8 +58,6 @@ VulkanObjectManager::~VulkanObjectManager()
VulkanObject VulkanObjectManager::CreateBuffer(VulkanMemoryManager::ResourceType resourceType,
uint32_t sizeInBytes, uint64_t batcherHash)
{
- std::lock_guard<std::mutex> lock(m_mutex);
-
VulkanObject result;
VkBufferCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@@ -92,10 +90,12 @@ VulkanObject VulkanObjectManager::CreateBuffer(VulkanMemoryManager::ResourceType
VkMemoryRequirements memReqs = {};
vkGetBufferMemoryRequirements(m_device, result.m_buffer, &memReqs);
- result.m_allocation = m_memoryManager.Allocate(resourceType, memReqs, batcherHash);
-
- CHECK_VK_CALL(vkBindBufferMemory(m_device, result.m_buffer, result.GetMemory(),
- result.GetAlignedOffset()));
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ result.m_allocation = m_memoryManager.Allocate(resourceType, memReqs, batcherHash);
+ CHECK_VK_CALL(vkBindBufferMemory(m_device, result.m_buffer, result.GetMemory(),
+ result.GetAlignedOffset()));
+ }
return result;
}
@@ -103,8 +103,6 @@ VulkanObject VulkanObjectManager::CreateBuffer(VulkanMemoryManager::ResourceType
VulkanObject VulkanObjectManager::CreateImage(VkImageUsageFlags usageFlags, VkFormat format,
VkImageAspectFlags aspectFlags, uint32_t width, uint32_t height)
{
- std::lock_guard<std::mutex> lock(m_mutex);
-
VulkanObject result;
VkImageCreateInfo imageCreateInfo = {};
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
@@ -124,11 +122,13 @@ VulkanObject VulkanObjectManager::CreateImage(VkImageUsageFlags usageFlags, VkFo
VkMemoryRequirements memReqs = {};
vkGetImageMemoryRequirements(m_device, result.m_image, &memReqs);
- result.m_allocation = m_memoryManager.Allocate(VulkanMemoryManager::ResourceType::Image,
- memReqs, 0 /* blockHash */);
-
- CHECK_VK_CALL(vkBindImageMemory(m_device, result.m_image,
- result.GetMemory(), result.GetAlignedOffset()));
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ result.m_allocation = m_memoryManager.Allocate(VulkanMemoryManager::ResourceType::Image,
+ memReqs, 0 /* blockHash */);
+ CHECK_VK_CALL(vkBindImageMemory(m_device, result.m_image,
+ result.GetMemory(), result.GetAlignedOffset()));
+ }
VkImageViewCreateInfo viewCreateInfo = {};
viewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
@@ -224,14 +224,13 @@ DescriptorSetGroup VulkanObjectManager::CreateDescriptorSetGroup(ref_ptr<VulkanG
void VulkanObjectManager::DestroyObject(VulkanObject object)
{
- std::lock_guard<std::mutex> lock(m_mutex);
- CHECK(!object.m_allocation->m_memoryBlock->m_isBlocked, ());
+ std::lock_guard<std::mutex> lock(m_destroyMutex);
m_queueToDestroy.push_back(std::move(object));
}
void VulkanObjectManager::DestroyDescriptorSetGroup(DescriptorSetGroup group)
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ std::lock_guard<std::mutex> lock(m_destroyMutex);
m_descriptorsToDestroy.push_back(std::move(group));
}
@@ -240,7 +239,7 @@ void VulkanObjectManager::CollectObjects()
std::vector<VulkanObject> queueToDestroy;
std::vector<DescriptorSetGroup> descriptorsToDestroy;
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ std::lock_guard<std::mutex> lock(m_destroyMutex);
std::swap(m_queueToDestroy, queueToDestroy);
std::swap(m_descriptorsToDestroy, descriptorsToDestroy);
}
diff --git a/drape/vulkan/vulkan_object_manager.hpp b/drape/vulkan/vulkan_object_manager.hpp
index 6a908bebe4..66ae2148f1 100644
--- a/drape/vulkan/vulkan_object_manager.hpp
+++ b/drape/vulkan/vulkan_object_manager.hpp
@@ -94,6 +94,7 @@ private:
std::map<SamplerKey, VkSampler> m_samplers;
std::mutex m_mutex;
+ std::mutex m_destroyMutex;
};
} // namespace vulkan
} // namespace dp
diff --git a/drape/vulkan/vulkan_pipeline.cpp b/drape/vulkan/vulkan_pipeline.cpp
index 3a81d3bb72..77b0179a17 100644
--- a/drape/vulkan/vulkan_pipeline.cpp
+++ b/drape/vulkan/vulkan_pipeline.cpp
@@ -191,7 +191,7 @@ void VulkanPipeline::Dump(VkDevice device)
if (!m_isChanged)
return;
- size_t constexpr kMaxCacheSizeInBytes = 200 * 1024;
+ size_t constexpr kMaxCacheSizeInBytes = 500 * 1024;
size_t cacheSize;
VkResult statusCode;
diff --git a/drape/vulkan/vulkan_texture.cpp b/drape/vulkan/vulkan_texture.cpp
index 52ed6ba73a..ce67cd8af9 100644
--- a/drape/vulkan/vulkan_texture.cpp
+++ b/drape/vulkan/vulkan_texture.cpp
@@ -161,6 +161,8 @@ void VulkanTexture::UploadData(ref_ptr<dp::GraphicsContext> context, uint32_t x,
VkCommandBuffer commandBuffer = vulkanContext->GetCurrentMemoryCommandBuffer();
CHECK(commandBuffer != nullptr, ());
+ Bind(context);
+
auto const sizeInBytes = GetBytesPerPixel(GetFormat()) * width * height;
VkBuffer sb;