Skip to content

Commit

Permalink
Vulkan: Decimate the texture allocator.
Browse files Browse the repository at this point in the history
Thin3D wasn't calling Begin/End, which lead to leaks eventually and OOM.

Was causing softgpu to crash.
  • Loading branch information
unknownbrackets committed Dec 24, 2017
1 parent 7f4da9b commit a7b3a1e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Common/Vulkan/VulkanMemory.cpp
Expand Up @@ -157,7 +157,7 @@ void VulkanPushBuffer::Unmap() {
} }


VulkanDeviceAllocator::VulkanDeviceAllocator(VulkanContext *vulkan, size_t minSlabSize, size_t maxSlabSize) VulkanDeviceAllocator::VulkanDeviceAllocator(VulkanContext *vulkan, size_t minSlabSize, size_t maxSlabSize)
: vulkan_(vulkan), lastSlab_(0), minSlabSize_(minSlabSize), maxSlabSize_(maxSlabSize), memoryTypeIndex_(UNDEFINED_MEMORY_TYPE), destroyed_(false) { : vulkan_(vulkan), minSlabSize_(minSlabSize), maxSlabSize_(maxSlabSize) {
assert((minSlabSize_ & (SLAB_GRAIN_SIZE - 1)) == 0); assert((minSlabSize_ & (SLAB_GRAIN_SIZE - 1)) == 0);
} }


Expand Down Expand Up @@ -290,7 +290,7 @@ int VulkanDeviceAllocator::ComputeUsagePercent() const {
blocksUsed += slabs_[i].usage[j] != 0 ? 1 : 0; blocksUsed += slabs_[i].usage[j] != 0 ? 1 : 0;
} }
} }
return 100 * blocksUsed / blockSum; return blockSum == 0 ? 0 : 100 * blocksUsed / blockSum;
} }


void VulkanDeviceAllocator::Free(VkDeviceMemory deviceMemory, size_t offset) { void VulkanDeviceAllocator::Free(VkDeviceMemory deviceMemory, size_t offset) {
Expand Down
6 changes: 3 additions & 3 deletions Common/Vulkan/VulkanMemory.h
Expand Up @@ -190,9 +190,9 @@ class VulkanDeviceAllocator {


VulkanContext *const vulkan_; VulkanContext *const vulkan_;
std::vector<Slab> slabs_; std::vector<Slab> slabs_;
size_t lastSlab_; size_t lastSlab_ = 0;
size_t minSlabSize_; size_t minSlabSize_;
const size_t maxSlabSize_; const size_t maxSlabSize_;
uint32_t memoryTypeIndex_; uint32_t memoryTypeIndex_ = UNDEFINED_MEMORY_TYPE;
bool destroyed_; bool destroyed_ = false;
}; };
2 changes: 2 additions & 0 deletions ext/native/thin3d/thin3d_vulkan.cpp
Expand Up @@ -779,6 +779,7 @@ void VKContext::BeginFrame() {
// OK, we now know that nothing is reading from this frame's data pushbuffer, // OK, we now know that nothing is reading from this frame's data pushbuffer,
push_->Reset(); push_->Reset();
push_->Begin(vulkan_); push_->Begin(vulkan_);
allocator_->Begin();


frame.descSets_.clear(); frame.descSets_.clear();
VkResult result = vkResetDescriptorPool(device_, frame.descriptorPool, 0); VkResult result = vkResetDescriptorPool(device_, frame.descriptorPool, 0);
Expand All @@ -792,6 +793,7 @@ void VKContext::WaitRenderCompletion(Framebuffer *fbo) {
void VKContext::EndFrame() { void VKContext::EndFrame() {
// Stop collecting data in the frame's data pushbuffer. // Stop collecting data in the frame's data pushbuffer.
push_->End(); push_->End();
allocator_->End();


renderManager_.Finish(); renderManager_.Finish();


Expand Down

0 comments on commit a7b3a1e

Please sign in to comment.