Fix issue with freeing resources

This commit is contained in:
Georg Hagen
2024-07-11 13:22:01 +02:00
parent 22cb48be89
commit 313b01db1b
16 changed files with 300 additions and 156 deletions

View File

@@ -7,13 +7,16 @@
#pragma once
// Workaround for libc++
#ifndef __cpp_lib_three_way_comparison
#define __cpp_lib_three_way_comparison 201907
#endif
#include "IShaderOwner.hpp"
#include "MemoryPool.hpp"
#include "Base/Wrapper.hpp"
#include "Vulkan/Image.hpp"
#include "Scene/Shader/DescriptorInputDescription.hpp"
#include <vulkan/vulkan.hpp>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
@@ -55,15 +58,15 @@ namespace OpenVulkano
vk::Device device = nullptr;
vk::Queue transferQueue = nullptr;
Array<FrameResources> frameResources;
std::vector<std::unique_ptr<MemoryAllocation>> allocations;
std::vector<std::unique_ptr<VulkanShader>> shaders;
std::vector<std::unique_ptr<VulkanGeometry>> geometries;
std::vector<std::unique_ptr<VulkanNode>> nodes;
MemoryPool memPool;
std::vector<Unique<VulkanShader>> shaders;
std::vector<Unique<VulkanGeometry>> geometries;
std::vector<Unique<VulkanNode>> nodes;
std::vector<Unique<VulkanTexture>> textures;
std::vector<Unique<VulkanCamera>> cameras;
std::vector<Unique<VulkanUniformBuffer>> uniforms;
std::mutex mutex;
vk::DeviceSize uniformBufferAlignment;
std::vector<std::vector<ManagedBuffer*>> toFree;
std::vector<ManagedBuffer*> recycleBuffers;
std::function<void(ManagedBuffer*)> freeFunction;
vk::DescriptorPool descriptorPool;
std::map<DescriptorSetLayoutBinding, vk::DescriptorSetLayout> descriptorSetLayoutCache;
std::map<vk::SamplerCreateInfo, vk::Sampler> samplerCache;
@@ -105,9 +108,7 @@ namespace OpenVulkano
void CopyDataToImage(vk::DeviceSize size, void* data, OpenVulkano::Vulkan::Image* image);
ManagedBuffer* CreateSharedMemoryBuffer(size_t size);
void FreeBuffer(ManagedBuffer* buffer);
MemoryPool::ManagedBufferPtr CreateSharedMemoryBuffer(size_t size);
[[nodiscard]] Context* GetContext() const { return context; }
@@ -118,23 +119,13 @@ namespace OpenVulkano
vk::Sampler CreateSampler(const vk::SamplerCreateInfo& samplerConfig);
protected: // Allocation management
void DoFreeBuffer(ManagedBuffer* buffer);
void FreeBuffers();
ManagedBuffer* CreateDeviceOnlyBufferWithData(vk::DeviceSize size, vk::BufferUsageFlagBits usage, const void* data);
MemoryPool::ManagedBufferPtr CreateDeviceOnlyBufferWithData(vk::DeviceSize size, vk::BufferUsageFlagBits usage, const void* data);
inline void RecordCopy(vk::Buffer src, vk::Buffer dest, vk::DeviceSize size)
{
vk::BufferCopy copyRegion = { 0, 0, size };
GetCmdBuffer().copyBuffer(src, dest, 1, &copyRegion);
}
ManagedBuffer* CreateBuffer(vk::DeviceSize size, const vk::BufferUsageFlags& usage, const vk::MemoryPropertyFlags& properties);
MemoryAllocation* CreateMemoryAllocation(size_t size, uint32_t type, bool addToCache = true);
MemoryAllocation* GetFreeMemoryAllocation(size_t size, vk::DeviceSize alignment, uint32_t type, bool createIfAllFull = true);
public:
vk::DescriptorSetLayout* GetDescriptorLayoutSet(const DescriptorSetLayoutBinding& descriptorSetLayoutBinding);