44#ifndef _NBL_ASSET_I_PIPELINE_LAYOUT_H_INCLUDED_
55#define _NBL_ASSET_I_PIPELINE_LAYOUT_H_INCLUDED_
66
7+ #include " nbl/macros.h"
8+ #include " nbl/core/declarations.h"
79
810#include < algorithm>
911#include < array>
1012
11- #include " nbl/macros .h"
12- #include " nbl/core/declarations.h "
13+ #include " nbl/asset/IDescriptorSetLayout .h"
14+ #include " nbl/builtin/hlsl/binding_info.hlsl "
1315
1416
1517namespace nbl ::asset
@@ -21,7 +23,7 @@ namespace nbl::asset
2123 however they serve as a fast path with regard to data upload from the
2224 CPU and data access from the GPU.
2325
24- Note that IrrlichtBaW limits push constant size to 128 bytes.
26+ Note that Nabla limits push constant size to 128 bytes.
2527
2628 Push Constants are an alternative to an UBO where it performs really poorly,
2729 mostly very small and very frequent updates. Examples of which are:
@@ -140,6 +142,44 @@ class IPipelineLayout
140142 return static_cast <int32_t >(i)-1 ;
141143 }
142144
145+ // utility function, if you compile shaders for specific layouts, not create layouts given shaders
146+ using desc_type_bitset_t = std::bitset<static_cast <size_t >(IDescriptor::E_TYPE::ET_COUNT)>;
147+ // TODO: add constraints for stage and creation flags, or just return the storage index & redirect?
148+ core::string getBindingInfoForHLSL (const hlsl::SBindingInfo& info, const desc_type_bitset_t allowedTypes=desc_type_bitset_t ().set()) const
149+ {
150+ if (info.set >=DESCRIPTOR_SET_COUNT)
151+ return " #error \" ::nbl::hlsl::SBindingInfo::set out of range!\" " ;
152+ const auto * layout = m_descSetLayouts[info.set ];
153+ if (!layout)
154+ return " #error \" ::nbl::hlsl::SBindingInfo::set layout is nullptr!\" " ;
155+ //
156+ using redirect_t = IDescriptorSetLayoutBase::CBindingRedirect;
157+ using storage_range_index_t = redirect_t ::storage_range_index_t ;
158+ const redirect_t * redirect;
159+ storage_range_index_t found;
160+ {
161+ const redirect_t ::binding_number_t binding (info.binding );
162+ for (auto t=0u ; t<static_cast <size_t >(IDescriptor::E_TYPE::ET_COUNT); t++)
163+ if (allowedTypes.test (t))
164+ {
165+ redirect = &layout->getDescriptorRedirect (static_cast <IDescriptor::E_TYPE>(t));
166+ found = redirect->findBindingStorageIndex (binding);
167+ if (found)
168+ break ;
169+ }
170+ if (!found && allowedTypes.test (static_cast <size_t >(IDescriptor::E_TYPE::ET_SAMPLER)))
171+ {
172+ redirect = &layout->getImmutableSamplerRedirect ();
173+ found = redirect->findBindingStorageIndex (binding);
174+ }
175+ if (!found)
176+ return " #error \" Could not find `::nbl::hlsl::SBindingInfo::binding` in `::nbl::hlsl::SBindingInfo::set`'s layout!\" " ;
177+ }
178+ const auto count = redirect->getCount (found);
179+ assert (count); // this layout should have never passed validation
180+ return " ::nbl::hlsl::ConstevalBindingInfo<" +std::to_string (info.set )+" ," +std::to_string (info.binding )+" ," +std::to_string (count)+" >" ;
181+ }
182+
143183 protected:
144184 IPipelineLayout (
145185 const std::span<const asset::SPushConstantRange> _pcRanges,
0 commit comments