Skip to content

Commit e963570

Browse files
author
devsh
committed
make Pipeline Layout return the descriptor sets layouts as a span and deprecate old APIs
1 parent b763d88 commit e963570

File tree

4 files changed

+50
-40
lines changed

4 files changed

+50
-40
lines changed

include/nbl/asset/IPipelineLayout.h

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,51 +89,56 @@ class IPipelineLayout
8989
public:
9090
static inline constexpr uint32_t DESCRIPTOR_SET_COUNT = 4u;
9191

92-
const DescLayoutType* getDescriptorSetLayout(uint32_t _set) const { return m_descSetLayouts[_set].get(); }
93-
core::SRange<const SPushConstantRange> getPushConstantRanges() const
94-
{
95-
if (m_pushConstantRanges)
96-
return {m_pushConstantRanges->data(), m_pushConstantRanges->data()+m_pushConstantRanges->size()};
97-
else
98-
return {nullptr, nullptr};
99-
}
92+
std::span<const DescLayoutType* const,DESCRIPTOR_SET_COUNT> getDescriptorSetLayouts() const
93+
{
94+
return std::span<const DescLayoutType* const,DESCRIPTOR_SET_COUNT>(&m_descSetLayouts[0].get(),DESCRIPTOR_SET_COUNT);
95+
}
96+
[[deprecated]] const DescLayoutType* getDescriptorSetLayout(uint32_t _set) const { return getDescriptorSetLayouts()[_set]; }
10097

101-
bool isCompatibleForPushConstants(const IPipelineLayout<DescLayoutType>* _other) const
102-
{
103-
if (getPushConstantRanges().size() != _other->getPushConstantRanges().size())
104-
return false;
98+
core::SRange<const SPushConstantRange> getPushConstantRanges() const
99+
{
100+
if (m_pushConstantRanges)
101+
return {m_pushConstantRanges->data(), m_pushConstantRanges->data()+m_pushConstantRanges->size()};
102+
else
103+
return {nullptr, nullptr};
104+
}
105105

106-
const size_t cnt = getPushConstantRanges().size();
107-
const SPushConstantRange* lhs = getPushConstantRanges().begin();
108-
const SPushConstantRange* rhs = _other->getPushConstantRanges().begin();
109-
for (size_t i = 0ull; i < cnt; ++i)
110-
if (lhs[i] != rhs[i])
106+
bool isCompatibleForPushConstants(const IPipelineLayout<DescLayoutType>* _other) const
107+
{
108+
if (getPushConstantRanges().size() != _other->getPushConstantRanges().size())
111109
return false;
112110

113-
return true;
114-
}
111+
const size_t cnt = getPushConstantRanges().size();
112+
const SPushConstantRange* lhs = getPushConstantRanges().begin();
113+
const SPushConstantRange* rhs = _other->getPushConstantRanges().begin();
114+
for (size_t i = 0ull; i < cnt; ++i)
115+
if (lhs[i] != rhs[i])
116+
return false;
115117

116-
//! Checks if `this` and `_other` are compatible for set `_setNum`. See https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#descriptorsets-compatibility for compatiblity rules.
117-
/**
118-
@returns Max value of `_setNum` for which the two pipeline layouts are compatible or -1 if they're not compatible at all.
119-
*/
120-
int32_t isCompatibleUpToSet(const uint32_t _setNum, const IPipelineLayout<DescLayoutType>* _other) const
121-
{
122-
if (!_setNum || (_setNum >= DESCRIPTOR_SET_COUNT)) //vulkan would also care about push constant ranges compatibility here
123-
return -1;
118+
return true;
119+
}
124120

125-
uint32_t i = 0u;
126-
for (; i <=_setNum; i++)
121+
//! Checks if `this` and `_other` are compatible for set `_setNum`. See https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#descriptorsets-compatibility for compatiblity rules.
122+
/**
123+
@returns Max value of `_setNum` for which the two pipeline layouts are compatible or -1 if they're not compatible at all.
124+
*/
125+
int32_t isCompatibleUpToSet(const uint32_t _setNum, const IPipelineLayout<DescLayoutType>* _other) const
127126
{
128-
const DescLayoutType* lhs = m_descSetLayouts[i].get();
129-
const DescLayoutType* rhs = _other->getDescriptorSetLayout(i);
127+
if (!_setNum || (_setNum >= DESCRIPTOR_SET_COUNT)) //vulkan would also care about push constant ranges compatibility here
128+
return -1;
130129

131-
const bool compatible = (lhs == rhs) || (lhs && lhs->isIdenticallyDefined(rhs));
132-
if (!compatible)
133-
break;
130+
uint32_t i = 0u;
131+
for (; i <=_setNum; i++)
132+
{
133+
const DescLayoutType* lhs = m_descSetLayouts[i].get();
134+
const DescLayoutType* rhs = _other->getDescriptorSetLayout(i);
135+
136+
const bool compatible = (lhs == rhs) || (lhs && lhs->isIdenticallyDefined(rhs));
137+
if (!compatible)
138+
break;
139+
}
140+
return static_cast<int32_t>(i)-1;
134141
}
135-
return static_cast<int32_t>(i)-1;
136-
}
137142

138143
protected:
139144
IPipelineLayout(

include/nbl/video/IDescriptorPool.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class NBL_API2 IDescriptorPool : public IBackendObject
7373
return nullptr;
7474
}
7575

76-
uint32_t createDescriptorSets(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, core::smart_refctd_ptr<IGPUDescriptorSet>* output);
76+
uint32_t createDescriptorSets(const std::span<const IGPUDescriptorSetLayout* const> layouts, core::smart_refctd_ptr<IGPUDescriptorSet>* output);
77+
[[deprecated]] inline uint32_t createDescriptorSets(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, core::smart_refctd_ptr<IGPUDescriptorSet>* output)
78+
{
79+
return createDescriptorSets({layouts,count},output);
80+
}
7781

7882
bool reset();
7983

src/nbl/video/IDescriptorPool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ IDescriptorPool::IDescriptorPool(core::smart_refctd_ptr<const ILogicalDevice>&&
2828
m_descriptorSetAllocator = core::IteratablePoolAddressAllocator<uint32_t>(m_descriptorSetAllocatorReservedSpace.get(), 0, 0, 1, m_creationParameters.maxSets, 1);
2929
}
3030

31-
uint32_t IDescriptorPool::createDescriptorSets(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, core::smart_refctd_ptr<IGPUDescriptorSet>* output)
31+
uint32_t IDescriptorPool::createDescriptorSets(const std::span<const IGPUDescriptorSetLayout* const> layouts, core::smart_refctd_ptr<IGPUDescriptorSet>* output)
3232
{
33+
const size_t count = layouts.size();
3334
core::vector<uint32_t> reverseMap(count,count);
3435

3536
core::vector<const IGPUDescriptorSetLayout*> repackedLayouts;
@@ -73,7 +74,7 @@ uint32_t IDescriptorPool::createDescriptorSets(uint32_t count, const IGPUDescrip
7374
else
7475
{
7576
// Free the allocated offsets for all the successfully allocated descriptor sets and the offset of the descriptor sets themselves.
76-
rewindLastStorageAllocations(successCount,offsets.data(),layouts);
77+
rewindLastStorageAllocations(successCount,offsets.data(),layouts.data());
7778
std::fill_n(output,count,nullptr);
7879
successCount = 0;
7980
}

0 commit comments

Comments
 (0)