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

@@ -19,7 +19,9 @@ namespace OpenVulkano::Vulkan
class VulkanTexture : public IRecordable, public Image
{
public:
static inline vk::SamplerCreateInfo DEFAULT_SAMPLER_CONFIG {};
Scene::Texture* m_texture = nullptr;
vk::Sampler m_sampler;
vk::DescriptorSet m_descriptorSet;
virtual void Init(ResourceManager* resManager, Scene::Texture* texture, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding)
@@ -29,16 +31,29 @@ namespace OpenVulkano::Vulkan
resManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this);
texture->updated = false;
m_sampler = resManager->CreateSampler(DEFAULT_SAMPLER_CONFIG);
SetDescriptorSet(resManager, descriptorSetLayout, binding);
texture->renderTexture = this;
}
void Close() override
{
Image::Close();
if (m_texture) m_texture->renderTexture = nullptr;
m_texture = nullptr;
}
void SetDescriptorSet(ResourceManager* resManager, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding)
{
// Setup Descriptor set
const vk::DescriptorSetAllocateInfo descSetAllocInfo = { ResourceManager::INSTANCE->descriptorPool, 1, descriptorSetLayout };
m_descriptorSet = resManager->GetContext()->device->device.allocateDescriptorSets(descSetAllocInfo)[0];
vk::DescriptorImageInfo imageInfo = { sampler, view, vk::ImageLayout::eShaderReadOnlyOptimal };
vk::DescriptorImageInfo imageInfo = { m_sampler, view, vk::ImageLayout::eShaderReadOnlyOptimal };
vk::WriteDescriptorSet writeDescriptorSet = { m_descriptorSet, binding.bindingId, 0, 1 };
writeDescriptorSet.descriptorType = static_cast<vk::DescriptorType>(binding.descriptorType);
writeDescriptorSet.pImageInfo = &imageInfo;
resManager->GetContext()->device->device.updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr);
texture->renderTexture = this;
}
void Record(VulkanDrawContext* context) override