Move sampler creation from image to resource manager and cache created samplers

This commit is contained in:
Georg Hagen
2024-07-09 12:31:52 +02:00
parent d48d60441a
commit d9a22236b4
5 changed files with 49 additions and 38 deletions

View File

@@ -95,6 +95,11 @@ namespace OpenVulkano::Vulkan
toFree.clear();
recycleBuffers.clear();
descriptorSetLayoutCache.clear();
for (auto& sampler : samplerCache)
{
device.destroy(sampler.second);
}
samplerCache.clear();
shaders.clear();
cmdBuffers = nullptr;
cmdPools = nullptr;
@@ -427,4 +432,11 @@ namespace OpenVulkano::Vulkan
vkBuffer->Init(buffer, uBuffer);
return vkBuffer;
}
vk::Sampler ResourceManager::CreateSampler(const vk::SamplerCreateInfo& samplerConfig)
{
auto& sampler = samplerCache[samplerConfig];
if (!sampler) sampler = device.createSampler(samplerConfig);
return sampler;
}
}

View File

@@ -6,6 +6,9 @@
#pragma once
// Workaround for libc++
#define __cpp_lib_three_way_comparison 201907
#include "vulkan/vulkan.hpp"
#include "Base/ICloseable.hpp"
#include "IShaderOwner.hpp"
@@ -62,6 +65,7 @@ namespace OpenVulkano
std::function<void(ManagedBuffer*)> freeFunction;
vk::DescriptorPool descriptorPool;
std::map<DescriptorSetLayoutBinding, vk::DescriptorSetLayout> descriptorSetLayoutCache;
std::map<vk::SamplerCreateInfo, vk::Sampler> samplerCache;
int buffers = -1, currentBuffer = -1;
@@ -108,6 +112,8 @@ namespace OpenVulkano
UniformBuffer* CreateUniformBuffer(const DescriptorSetLayoutBinding& binding, size_t size, void* data, uint32_t setId = 2);
vk::Sampler CreateSampler(const vk::SamplerCreateInfo& samplerConfig);
protected: // Allocation management
void DoFreeBuffer(ManagedBuffer* buffer);
@@ -127,9 +133,9 @@ namespace OpenVulkano
MemoryAllocation* GetFreeMemoryAllocation(size_t size, vk::DeviceSize alignment, uint32_t type, bool createIfAllFull = true);
public:
vk::DescriptorSetLayout* GetDescriptorLayoutSet(const DescriptorSetLayoutBinding& descriptorSetLayoutBinding);
public:
VulkanShader* CreateShader(Scene::Shader* shader);
};
}