diff --git a/drape/vulkan/vulkan_memory_manager.cpp b/drape/vulkan/vulkan_memory_manager.cpp index 08cb4a56d3..6015112b62 100644 --- a/drape/vulkan/vulkan_memory_manager.cpp +++ b/drape/vulkan/vulkan_memory_manager.cpp @@ -76,14 +76,21 @@ VulkanMemoryManager::~VulkanMemoryManager() for (size_t i = 0; i < kResourcesCount; ++i) { for (auto const & b : m_freeBlocks[i]) + { + DecrementTotalAllocationsCount(); vkFreeMemory(m_device, b->m_memory, nullptr); + } for (auto const & p : m_memory[i]) { for (auto const & b : p.second) + { + DecrementTotalAllocationsCount(); vkFreeMemory(m_device, b->m_memory, nullptr); + } } } + ASSERT_EQUAL(m_totalAllocationCounter, 0, ()); } boost::optional VulkanMemoryManager::GetMemoryTypeIndex(uint32_t typeBits, @@ -203,6 +210,7 @@ VulkanMemoryManager::AllocationPtr VulkanMemoryManager::Allocate(ResourceType re memAllocInfo.pNext = nullptr; memAllocInfo.allocationSize = blockSize; memAllocInfo.memoryTypeIndex = memoryTypeIndex.value(); + IncrementTotalAllocationsCount(); CHECK_VK_CALL(vkAllocateMemory(m_device, &memAllocInfo, nullptr, &memory)); m_sizes[static_cast(resourceType)] += blockSize; @@ -262,6 +270,7 @@ void VulkanMemoryManager::Deallocate(AllocationPtr ptr) { CHECK_LESS_OR_EQUAL(memoryBlock->m_blockSize, m_sizes[resourceIndex], ()); m_sizes[resourceIndex] -= memoryBlock->m_blockSize; + DecrementTotalAllocationsCount(); vkFreeMemory(m_device, memoryBlock->m_memory, nullptr); } else @@ -302,6 +311,7 @@ void VulkanMemoryManager::EndDeallocationSession() { CHECK_LESS_OR_EQUAL(b->m_blockSize, m_sizes[i], ()); m_sizes[i] -= b->m_blockSize; + DecrementTotalAllocationsCount(); vkFreeMemory(m_device, b->m_memory, nullptr); } else @@ -326,5 +336,22 @@ void VulkanMemoryManager::EndDeallocationSession() std::sort(fm.begin(), fm.end(), &Less); } } + +void VulkanMemoryManager::IncrementTotalAllocationsCount() +{ + ++m_totalAllocationCounter; + CHECK_LESS_OR_EQUAL(m_totalAllocationCounter, m_deviceLimits.maxMemoryAllocationCount, ()); +} + +void VulkanMemoryManager::DecrementTotalAllocationsCount() +{ + CHECK_GREATER(m_totalAllocationCounter, 0, ()); + --m_totalAllocationCounter; +} + +VkPhysicalDeviceLimits const & VulkanMemoryManager::GetDeviceLimits() const +{ + return m_deviceLimits; +} } // namespace vulkan } // namespace dp diff --git a/drape/vulkan/vulkan_memory_manager.hpp b/drape/vulkan/vulkan_memory_manager.hpp index 574663b44d..f379aae42d 100644 --- a/drape/vulkan/vulkan_memory_manager.hpp +++ b/drape/vulkan/vulkan_memory_manager.hpp @@ -78,15 +78,20 @@ public: uint32_t GetSizeAlignment(VkMemoryRequirements const & memReqs) const; static uint32_t GetAligned(uint32_t value, uint32_t alignment); + VkPhysicalDeviceLimits const & GetDeviceLimits() const; + private: boost::optional GetMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) const; + void IncrementTotalAllocationsCount(); + void DecrementTotalAllocationsCount(); VkDevice const m_device; VkPhysicalDeviceLimits const m_deviceLimits; VkPhysicalDeviceMemoryProperties const m_memoryProperties; bool m_isInDeallocationSession = false; uint32_t m_deallocationSessionMask = 0; + uint32_t m_totalAllocationCounter = 0; using MemoryBlocks = std::vector>; std::array, kResourcesCount> m_memory; diff --git a/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp b/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp index 5eb1d4c904..972940b55a 100644 --- a/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp +++ b/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp @@ -93,6 +93,9 @@ public: auto const indexType = dp::IndexStorage::IsSupported32bit() ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16; vkCmdBindIndexBuffer(commandBuffer, vulkanIndexBuffer, 0, indexType); + CHECK_LESS_OR_EQUAL(range.m_idxStart + range.m_idxCount, + m_objectManager->GetMemoryManager().GetDeviceLimits().maxDrawIndexedIndexValue, ()); + vkCmdDrawIndexed(commandBuffer, range.m_idxCount, 1, range.m_idxStart, 0, 0); } diff --git a/shaders/vulkan_program_params.cpp b/shaders/vulkan_program_params.cpp index 159ccc47a3..9aa4a7aef4 100644 --- a/shaders/vulkan_program_params.cpp +++ b/shaders/vulkan_program_params.cpp @@ -10,7 +10,7 @@ namespace vulkan { namespace { -uint32_t constexpr kUniformBufferSizeInBytes = 64 * 1024; +uint32_t constexpr kUniformBufferSizeInBytes = 16 * 1024; VulkanProgramParamsSetter::UniformBuffer CreateUniformBuffer(VkDevice device, ref_ptr objectManager,