From 7e1f907826b8c7b53d8519315621fd661d110458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 4 May 2023 10:25:16 +0200 Subject: [PATCH] VulkanPushPool: Sprinkle a couple of asserts. --- Common/GPU/Vulkan/VulkanMemory.cpp | 3 +++ Common/GPU/Vulkan/VulkanMemory.h | 1 + 2 files changed, 4 insertions(+) diff --git a/Common/GPU/Vulkan/VulkanMemory.cpp b/Common/GPU/Vulkan/VulkanMemory.cpp index 06c834dd4ca9..1a718c95a7de 100644 --- a/Common/GPU/Vulkan/VulkanMemory.cpp +++ b/Common/GPU/Vulkan/VulkanMemory.cpp @@ -323,6 +323,7 @@ VulkanPushPool::Block VulkanPushPool::CreateBlock(size_t size) { result = vmaMapMemory(vulkan_->Allocator(), block.allocation, (void **)(&block.writePtr)); _assert_(result == VK_SUCCESS); + _assert_msg_(block.writePtr != nullptr, "VulkanPushPool: Failed to map memory on block of size %d", (int)block.size); return block; } @@ -384,6 +385,7 @@ void VulkanPushPool::NextBlock(VkDeviceSize allocationSize) { block.used = allocationSize; block.lastUsed = time_now_d(); block.frameIndex = curFrameIndex; + _assert_(block.writePtr != nullptr); return; } curBlockIndex_++; @@ -391,6 +393,7 @@ void VulkanPushPool::NextBlock(VkDeviceSize allocationSize) { double start = time_now_d(); VkDeviceSize newBlockSize = std::max(originalBlockSize_ * 2, (VkDeviceSize)RoundUpToPowerOf2((uint32_t)allocationSize)); + // We're still here and ran off the end of blocks. Create a new one. blocks_.push_back(CreateBlock(newBlockSize)); blocks_.back().frameIndex = curFrameIndex; diff --git a/Common/GPU/Vulkan/VulkanMemory.h b/Common/GPU/Vulkan/VulkanMemory.h index 151c31ab6025..766f497a7930 100644 --- a/Common/GPU/Vulkan/VulkanMemory.h +++ b/Common/GPU/Vulkan/VulkanMemory.h @@ -107,6 +107,7 @@ class VulkanPushBuffer : public VulkanMemoryManager { // Simple memory pushbuffer pool that can share blocks between the "frames", to reduce the impact of push memory spikes - // a later frame can gobble up redundant buffers from an earlier frame even if they don't share frame index. +// NOT thread safe! Can only be used from one thread (our main thread). class VulkanPushPool : public VulkanMemoryManager { public: VulkanPushPool(VulkanContext *vulkan, const char *name, size_t originalBlockSize, VkBufferUsageFlags usage);