Skip to content

Commit faeff6d

Browse files
author
devsh
committed
better use of Descriptor Set Layout introspection APIs
1 parent 38ab25a commit faeff6d

File tree

1 file changed

+38
-54
lines changed

1 file changed

+38
-54
lines changed

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ void UI::handleKeyEvents(const SUpdateParameters& params) const
733733

734734
UI::UI(SCreationParameters&& creationParams)
735735
{
736+
system::logger_opt_ptr logger = creationParams.utilities->getLogger();
737+
736738
auto validateResourcesInfo = [&]() -> bool
737739
{
738740
auto* pipelineLayout = creationParams.pipelineLayout.get();
@@ -741,17 +743,18 @@ UI::UI(SCreationParameters&& creationParams)
741743
{
742744
auto validateResource = [&]<IDescriptor::E_TYPE descriptorType>(const IGPUDescriptorSetLayout* const descriptorSetLayout)
743745
{
746+
static_assert(descriptorType!=IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER, "Explicitly not supported.");
744747
constexpr std::string_view typeLiteral = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? "ET_SAMPLED_IMAGE" : "ET_SAMPLER",
745748
ixLiteral = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? "texturesBindingIx" : "samplersBindingIx";
746749

747750
// we need to check if there is at least single "descriptorType" resource, if so we can validate the resource further
748-
auto anyBindingCount = [&creationParams = creationParams, &log = std::as_const(typeLiteral)](const IDescriptorSetLayoutBase::CBindingRedirect* redirect, bool logError = true) -> bool
751+
auto anyBindingCount = [logger,&creationParams = creationParams, &log = std::as_const(typeLiteral)](const IDescriptorSetLayoutBase::CBindingRedirect* redirect, bool logError = true) -> bool
749752
{
750753
bool ok = redirect->getBindingCount();
751754

752755
if (!ok && logError)
753756
{
754-
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!", ILogger::ELL_ERROR, log.data());
757+
logger.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!", ILogger::ELL_ERROR, log.data());
755758
return false;
756759
}
757760

@@ -760,11 +763,12 @@ UI::UI(SCreationParameters&& creationParams)
760763

761764
if(!descriptorSetLayout)
762765
{
763-
creationParams.utilities->getLogger()->log("Provided descriptor set layout for IDescriptor::E_TYPE::%s is nullptr!", ILogger::ELL_ERROR, typeLiteral.data());
766+
logger.log("Provided descriptor set layout for IDescriptor::E_TYPE::%s is nullptr!", ILogger::ELL_ERROR, typeLiteral.data());
764767
return false;
765768
}
766769

767-
const auto* redirect = &descriptorSetLayout->getDescriptorRedirect(descriptorType);
770+
using redirect_t = IDescriptorSetLayoutBase::CBindingRedirect;
771+
const redirect_t* redirect = &descriptorSetLayout->getDescriptorRedirect(descriptorType);
768772

769773
if constexpr (descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE)
770774
{
@@ -782,57 +786,37 @@ UI::UI(SCreationParameters&& creationParams)
782786
}
783787
}
784788

785-
const auto bindingCount = redirect->getBindingCount();
786-
787-
bool ok = false;
788-
for (uint32_t i = 0u; i < bindingCount; ++i)
789+
const redirect_t::binding_number_t requestedBinding(descriptorType==IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? creationParams.resources.texturesInfo.bindingIx:creationParams.resources.samplersInfo.bindingIx);
790+
const auto storageIndex = redirect->findBindingStorageIndex(requestedBinding);
791+
if (!storageIndex)
789792
{
790-
const auto rangeStorageIndex = IDescriptorSetLayoutBase::CBindingRedirect::storage_range_index_t(i);
791-
const auto binding = redirect->getBinding(rangeStorageIndex);
792-
const auto requestedBindingIx = descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? creationParams.resources.texturesInfo.bindingIx : creationParams.resources.samplersInfo.bindingIx;
793-
794-
if (binding.data == requestedBindingIx)
795-
{
796-
const auto count = redirect->getCount(binding);
797-
798-
if(!count)
799-
{
800-
creationParams.utilities->getLogger()->log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index but the binding resource count == 0u!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
801-
return false;
802-
}
803-
804-
if constexpr (descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE)
805-
creationParams.resources.texturesCount = count;
806-
else
807-
creationParams.resources.samplersCount = count;
808-
809-
const auto stage = redirect->getStageFlags(binding);
810-
811-
if(!stage.hasFlags(creationParams.resources.RequiredShaderStageFlags))
812-
{
813-
creationParams.utilities->getLogger()->log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index but doesn't meet stage flags requirements!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
814-
return false;
815-
}
816-
817-
const auto creation = redirect->getCreateFlags(rangeStorageIndex);
818-
819-
if (!creation.hasFlags(descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? creationParams.resources.TexturesRequiredCreateFlags : creationParams.resources.SamplersRequiredCreateFlags))
820-
{
821-
creationParams.utilities->getLogger()->log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index but doesn't meet create flags requirements!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
822-
return false;
823-
}
824-
825-
ok = true;
826-
break;
827-
}
793+
logger.log("No IDescriptor::E_TYPE::%s binding exists for requested `creationParams.resources.%s=%d` in the Provided descriptor set layout!",ILogger::ELL_ERROR,typeLiteral.data(),ixLiteral.data(),requestedBinding.data);
794+
return false;
828795
}
829-
830-
if (!ok)
796+
797+
const auto creation = redirect->getCreateFlags(storageIndex);
798+
if (!creation.hasFlags(descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE ? creationParams.resources.TexturesRequiredCreateFlags : creationParams.resources.SamplersRequiredCreateFlags))
799+
{
800+
logger.log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index but doesn't meet create flags requirements!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
801+
return false;
802+
}
803+
const auto stage = redirect->getStageFlags(storageIndex);
804+
if (!stage.hasFlags(creationParams.resources.RequiredShaderStageFlags))
805+
{
806+
logger.log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index but doesn't meet stage flags requirements!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
807+
return false;
808+
}
809+
const auto count = redirect->getCount(storageIndex);
810+
if(!count)
831811
{
832-
creationParams.utilities->getLogger()->log("Provided descriptor set layout has no IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index or it is invalid!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
812+
logger.log("Provided descriptor set layout has IDescriptor::E_TYPE::%s binding for requested `creationParams.resources.%s` index but the binding resource count == 0u!", ILogger::ELL_ERROR, typeLiteral.data(), ixLiteral.data());
833813
return false;
834814
}
835815

816+
if constexpr (descriptorType == IDescriptor::E_TYPE::ET_SAMPLED_IMAGE)
817+
creationParams.resources.texturesCount = count;
818+
else
819+
creationParams.resources.samplersCount = count;
836820
return true;
837821
};
838822

@@ -861,11 +845,11 @@ UI::UI(SCreationParameters&& creationParams)
861845
});
862846

863847
for (const auto& [ok, error] : validation)
864-
if (!ok)
865-
{
866-
creationParams.utilities->getLogger()->log(error, ILogger::ELL_ERROR);
867-
assert(false);
868-
}
848+
if (!ok)
849+
{
850+
logger.log(error, ILogger::ELL_ERROR);
851+
assert(false);
852+
}
869853

870854

871855
// Dear ImGui context

0 commit comments

Comments
 (0)