Improve texture binding handling

This commit is contained in:
2024-07-05 09:50:19 +02:00
parent eb96d7d674
commit 86e7681a8d
4 changed files with 45 additions and 9 deletions

View File

@@ -380,7 +380,7 @@ namespace OpenVulkano::Vulkan
{
VulkanTexture* vkTexture = new VulkanTexture();
vkTexture->Init(this, texture, GetDescriptorLayoutSet(Scene::Texture::DESCRIPTOR_SET_LAYOUT_BINDING), Scene::Texture::DESCRIPTOR_SET_LAYOUT_BINDING, 2);
vkTexture->Init(this, texture, GetDescriptorLayoutSet(Scene::Texture::DESCRIPTOR_SET_LAYOUT_BINDING), Scene::Texture::DESCRIPTOR_SET_LAYOUT_BINDING);
return vkTexture;
}

View File

@@ -20,12 +20,10 @@ namespace OpenVulkano::Vulkan
public:
Scene::Texture* m_texture = nullptr;
vk::DescriptorSet m_descriptorSet;
uint32_t m_setId;
virtual void Init(ResourceManager* resManager, Scene::Texture* texture, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding, uint32_t setId)
virtual void Init(ResourceManager* resManager, Scene::Texture* texture, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding)
{
m_texture = texture;
m_setId = setId;
Image::Init(resManager->GetContext()->device.get(), { texture->resolution.x, texture->resolution.y, texture->resolution.z });
resManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this);
texture->updated = false;
@@ -44,7 +42,37 @@ namespace OpenVulkano::Vulkan
void Record(VulkanDrawContext* context) override
{
context->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, context->GetShader()->pipelineLayout, m_setId, 1, &m_descriptorSet, 0, nullptr);
int setId = -1, i = 0;
for (const auto& descriptorSet : context->GetShader()->shader->descriptorSets)
{
for (const auto& descriptor : descriptorSet)
{
if (descriptor.descriptorType < 6)
{
if (setId != -1) [[unlikely]]
{
Logger::RENDER->error("Found multiple possible descriptor set for texture! Use 'Record(VulkanDrawContext* context, int setId)' explicitly when using multiple sets containing textures!");
}
setId = i;
break;
}
}
i++;
}
if (setId == -1) [[unlikely]]
{
Logger::RENDER->error("Failed to discover setId for texture binding.");
return;
}
else [[likely]]
{
Record(context, setId + 2); // Set 0 and 1 are automatically bound special sets for the camera and the node
}
}
void Record(VulkanDrawContext* context, int setId)
{
context->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, context->GetShader()->pipelineLayout, setId, 1, &m_descriptorSet, 0, nullptr);
}
};