Skip to content

Commit 067e8a3

Browse files
author
devsh
committed
make pipeline layouts const and improve the getBindingInfoForHLSL
1 parent bb757d8 commit 067e8a3

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

include/nbl/asset/ICPUComputePipeline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
2525
{
2626
if (!params.layout)
2727
return nullptr;
28-
auto retval = new ICPUComputePipeline(core::smart_refctd_ptr<ICPUPipelineLayout>(params.layout));
28+
auto retval = new ICPUComputePipeline(core::smart_refctd_ptr<const ICPUPipelineLayout>(params.layout));
2929
if (!retval->setSpecInfo(params.shader))
3030
{
3131
retval->drop();
@@ -48,7 +48,7 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
4848
using base_t::base_t;
4949
virtual ~ICPUComputePipeline() = default;
5050

51-
base_t* clone_impl(core::smart_refctd_ptr<ICPUPipelineLayout>&& layout) const override
51+
base_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const override
5252
{
5353
return new ICPUComputePipeline(std::move(layout));
5454
}
@@ -57,7 +57,7 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
5757
{
5858
if (ix!=0)
5959
return m_stages[0].shader.get();
60-
return m_layout.get();
60+
return const_cast<ICPUPipelineLayout*>(m_layout.get());
6161
}
6262

6363
inline int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const override

include/nbl/asset/ICPUGraphicsPipeline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPip
6565
using base_t::base_t;
6666
~ICPUGraphicsPipeline() = default;
6767

68-
base_t* clone_impl(core::smart_refctd_ptr<ICPUPipelineLayout>&& layout) const override
68+
base_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const override
6969
{
7070
std::array<ICPUShader::SSpecInfo,GRAPHICS_SHADER_STAGE_COUNT> _shaders;
7171
for (auto i=0; i<GRAPHICS_SHADER_STAGE_COUNT; i++)
@@ -80,7 +80,7 @@ class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPip
8080
inline IAsset* getDependant_impl(const size_t ix) override
8181
{
8282
if (ix==0)
83-
return m_layout.get();
83+
return const_cast<ICPUPipelineLayout*>(m_layout.get());
8484
if (ix==1)
8585
return m_renderpass.get();
8686
size_t stageCount = 0;

include/nbl/asset/ICPUPipeline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class ICPUPipeline : public IAsset, public PipelineNonAssetBase
5151
ICPUPipelineLayout* getLayout()
5252
{
5353
assert(isMutable());
54-
return PipelineNonAssetBase::m_layout.get();
54+
return const_cast<ICPUPipelineLayout*>(PipelineNonAssetBase::m_layout.get());
5555
}
5656
const ICPUPipelineLayout* getLayout() const { return PipelineNonAssetBase::m_layout.get(); }
5757

58-
inline void setLayout(core::smart_refctd_ptr<ICPUPipelineLayout>&& _layout)
58+
inline void setLayout(core::smart_refctd_ptr<const ICPUPipelineLayout>&& _layout)
5959
{
6060
assert(isMutable());
6161
PipelineNonAssetBase::m_layout = std::move(_layout);
@@ -117,7 +117,7 @@ class ICPUPipeline : public IAsset, public PipelineNonAssetBase
117117
using PipelineNonAssetBase::PipelineNonAssetBase;
118118
virtual ~ICPUPipeline() = default;
119119

120-
virtual this_t* clone_impl(core::smart_refctd_ptr<ICPUPipelineLayout>&& layout) const = 0;
120+
virtual this_t* clone_impl(core::smart_refctd_ptr<const ICPUPipelineLayout>&& layout) const = 0;
121121
virtual int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const = 0;
122122

123123
struct ShaderStage {

include/nbl/asset/IPipeline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class IPipeline
3535
struct SCreationParams
3636
{
3737
public:
38-
PipelineLayout* layout = nullptr;
38+
const PipelineLayout* layout = nullptr;
3939

4040
protected:
4141
// This is not public to make sure that different pipelines only get the enums they support
@@ -107,9 +107,9 @@ class IPipeline
107107
inline const PipelineLayout* getLayout() const {return m_layout.get();}
108108

109109
protected:
110-
inline IPipeline(core::smart_refctd_ptr<PipelineLayout>&& _layout) : m_layout(std::move(_layout)) {}
110+
inline IPipeline(core::smart_refctd_ptr<const PipelineLayout>&& _layout) : m_layout(std::move(_layout)) {}
111111

112-
core::smart_refctd_ptr<PipelineLayout> m_layout;
112+
core::smart_refctd_ptr<const PipelineLayout> m_layout;
113113
};
114114

115115
}

include/nbl/asset/IPipelineLayout.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,41 +143,51 @@ class IPipelineLayout
143143
}
144144

145145
// 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)>;
146+
struct SBindingKey
147+
{
148+
using type_bitset_t = std::bitset<static_cast<size_t>(IDescriptor::E_TYPE::ET_COUNT)>;
149+
150+
hlsl::SBindingInfo binding = {};
151+
core::bitflag<IShader::E_SHADER_STAGE> requiredStages = IShader::E_SHADER_STAGE::ESS_UNKNOWN;
152+
// could have just initialized with `~type_bitset_t()` in C++23
153+
type_bitset_t allowedTypes = type_bitset_t((0x1u<<static_cast<size_t>(IDescriptor::E_TYPE::ET_COUNT))-1);
154+
};
147155
// 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
156+
core::string getBindingInfoForHLSL(const SBindingKey& key) const
149157
{
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];
158+
if (key.binding.set>=DESCRIPTOR_SET_COUNT)
159+
return "#error \"IPipelineLayout::SBindingKey::binding::set out of range!\"";
160+
const auto* layout = m_descSetLayouts[key.binding.set].get();
153161
if (!layout)
154-
return "#error \"::nbl::hlsl::SBindingInfo::set layout is nullptr!\"";
162+
return "#error \"IPipelineLayout::SBindingKey::binding::set layout is nullptr!\"";
155163
//
156164
using redirect_t = IDescriptorSetLayoutBase::CBindingRedirect;
157165
using storage_range_index_t = redirect_t::storage_range_index_t;
158166
const redirect_t* redirect;
159167
storage_range_index_t found;
160168
{
161-
const redirect_t::binding_number_t binding(info.binding);
169+
const redirect_t::binding_number_t binding(key.binding.binding);
162170
for (auto t=0u; t<static_cast<size_t>(IDescriptor::E_TYPE::ET_COUNT); t++)
163-
if (allowedTypes.test(t))
171+
if (key.allowedTypes.test(t))
164172
{
165173
redirect = &layout->getDescriptorRedirect(static_cast<IDescriptor::E_TYPE>(t));
166174
found = redirect->findBindingStorageIndex(binding);
167175
if (found)
168176
break;
169177
}
170-
if (!found && allowedTypes.test(static_cast<size_t>(IDescriptor::E_TYPE::ET_SAMPLER)))
178+
if (!found && key.allowedTypes.test(static_cast<size_t>(IDescriptor::E_TYPE::ET_SAMPLER)))
171179
{
172180
redirect = &layout->getImmutableSamplerRedirect();
173181
found = redirect->findBindingStorageIndex(binding);
174182
}
175183
if (!found)
176-
return "#error \"Could not find `::nbl::hlsl::SBindingInfo::binding` in `::nbl::hlsl::SBindingInfo::set`'s layout!\"";
184+
return "#error \"Could not find `IPipelineLayout::SBindingKey::binding::binding` in `IPipelineLayout::SBindingKey::binding::set`'s layout!\"";
177185
}
186+
if (redirect->getStageFlags(found).hasFlags(key.requiredStages))
187+
return "#error \"Binding found in the layout doesn't have all the `IPipelineLayout::SBindingKey::binding::requiredStages` flags!\"";
178188
const auto count = redirect->getCount(found);
179189
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)+">";
190+
return "::nbl::hlsl::ConstevalBindingInfo<"+std::to_string(key.binding.set)+","+std::to_string(key.binding.binding)+","+std::to_string(count)+">";
181191
}
182192

183193
protected:

0 commit comments

Comments
 (0)