Skip to content

Commit 3c63d01

Browse files
committed
update UI's validation to cover both immutable & non-immutable samplers
1 parent eaad1cd commit 3c63d01

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -675,49 +675,67 @@ namespace nbl::ext::imgui
675675
constexpr std::string_view typeLiteral = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? "ET_SAMPLED_IMAGE" : "ET_SAMPLER",
676676
ixLiteral = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? "texturesBindingIx" : "samplersBindingIx";
677677

678+
auto anyBindingCount = [&m_creationParams = m_creationParams, &log = std::as_const(typeLiteral)](const IDescriptorSetLayoutBase::CBindingRedirect* redirect) -> bool
679+
{
680+
if (redirect->getBindingCount())
681+
{
682+
m_creationParams.utilities->getLogger()->log("Provided descriptor set layout has no bindings for IDescriptor::E_TYPE::%s, you are required to provide at least single default ImGUI Font Atlas texture resource & corresponsing sampler resource!", system::ILogger::ELL_ERROR, log.data());
683+
return false;
684+
}
685+
686+
return true;
687+
};
688+
678689
if(!descriptorSetLayout)
679690
{
680691
m_creationParams.utilities->getLogger()->log("Provided descriptor set layout for IDescriptor::E_TYPE::%s is nullptr!", system::ILogger::ELL_ERROR, typeLiteral.data());
681692
return false;
682693
}
683694

684-
const auto& redirect = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? descriptorSetLayout->getDescriptorRedirect(descriptorType)
685-
: descriptorSetLayout->getImmutableSamplerRedirect(); // TODO: now I cannot assume it, need to check ordinary samplers as well
686-
687-
const auto bindingCount = redirect.getBindingCount();
695+
const auto* redirect = &descriptorSetLayout->getDescriptorRedirect(descriptorType);
688696

689-
if (!bindingCount)
697+
if constexpr (descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE)
698+
if (!anyBindingCount(redirect))
699+
return false;
700+
else
690701
{
691-
m_creationParams.utilities->getLogger()->log("Provided descriptor set layout has no bindings for IDescriptor::E_TYPE::%s, you are required to provide at least single one for default ImGUI Font Atlas texture!", system::ILogger::ELL_ERROR, typeLiteral.data());
692-
return false;
702+
if (!anyBindingCount(redirect))
703+
{
704+
redirect = &descriptorSetLayout->getImmutableSamplerRedirect(); // we must give it another try & request to look for immutable samplers
705+
706+
if (!anyBindingCount(redirect))
707+
return false;
708+
}
693709
}
694710

711+
const auto bindingCount = redirect->getBindingCount();
712+
695713
bool ok = false;
696714
for (uint32_t i = 0u; i < bindingCount; ++i)
697715
{
698716
const auto rangeStorageIndex = IDescriptorSetLayoutBase::CBindingRedirect::storage_range_index_t(i);
699-
const auto binding = redirect.getBinding(rangeStorageIndex);
717+
const auto binding = redirect->getBinding(rangeStorageIndex);
700718
const auto requestedBindingIx = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? m_creationParams.resources.textures.bindingIx : m_creationParams.resources.samplers.bindingIx;
701719

702720
if (binding.data == requestedBindingIx)
703721
{
704-
const auto count = redirect.getCount(binding);
722+
const auto count = redirect->getCount(binding);
705723

706724
if (count != m_creationParams.resources.count)
707725
{
708726
m_creationParams.utilities->getLogger()->log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `m_creationParams.resources.%s` index but with different binding count!", system::ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
709727
return false;
710728
}
711729

712-
const auto stage = redirect.getStageFlags(binding);
730+
const auto stage = redirect->getStageFlags(binding);
713731

714732
if(!stage.hasFlags(m_creationParams.resources.RESOURCES_REQUIRED_STAGE_FLAGS))
715733
{
716734
m_creationParams.utilities->getLogger()->log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `m_creationParams.resources.%s` index but doesn't meet stage flags requirements!", system::ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
717735
return false;
718736
}
719737

720-
const auto create = redirect.getCreateFlags(rangeStorageIndex);
738+
const auto create = redirect->getCreateFlags(rangeStorageIndex);
721739

722740
if (!create.hasFlags(descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? m_creationParams.resources.TEXTURES_REQUIRED_CREATE_FLAGS : m_creationParams.resources.SAMPLERS_REQUIRED_CREATE_FLAGS))
723741
{

0 commit comments

Comments
 (0)