Skip to content

Commit d0052ac

Browse files
Merge branch 'suballocdescriptorset' of github.com:Devsh-Graphics-Programming/Nabla
2 parents f3df85d + aca4c74 commit d0052ac

File tree

10 files changed

+563
-15
lines changed

10 files changed

+563
-15
lines changed

include/nbl/asset/IDescriptorSetLayout.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class IDescriptorSetLayout : public virtual core::IReferenceCounted // TODO: tr
118118
return m_stageFlags[index.data];
119119
}
120120

121+
inline core::bitflag<typename SBinding::E_CREATE_FLAGS> getCreateFlags(const storage_range_index_t index) const
122+
{
123+
assert(index.data < m_count);
124+
return m_createFlags[index.data];
125+
}
126+
121127
inline uint32_t getCount(const storage_range_index_t index) const
122128
{
123129
assert(index.data < m_count);

include/nbl/core/alloc/address_allocator_traits.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ namespace nbl::core
5353
}
5454
}
5555

56+
static inline void multi_alloc_addr(AddressAlloc& alloc, uint32_t count, size_type* outAddresses, const size_type* bytes,
57+
const size_type alignment, const size_type* hint=nullptr) noexcept
58+
{
59+
for (uint32_t i=0; i<count; i++)
60+
{
61+
if (outAddresses[i]!=AddressAlloc::invalid_address)
62+
continue;
63+
64+
outAddresses[i] = alloc.alloc_addr(bytes[i],alignment,hint ? hint[i]:0ull);
65+
}
66+
}
67+
5668
static inline void multi_free_addr(AddressAlloc& alloc, uint32_t count, const size_type* addr, const size_type* bytes) noexcept
5769
{
5870
for (uint32_t i=0; i<count; i++)
@@ -186,6 +198,14 @@ namespace nbl::core
186198
alloc,std::min(count-i,maxMultiOps),outAddresses+i,bytes+i,alignment+i,hint ? (hint+i):nullptr);
187199
}
188200

201+
static inline void multi_alloc_addr(AddressAlloc& alloc, uint32_t count, size_type* outAddresses,
202+
const size_type* bytes, const size_type alignment, const size_type* hint=nullptr) noexcept
203+
{
204+
for (uint32_t i=0; i<count; i+=maxMultiOps)
205+
impl::address_allocator_traits_base<AddressAlloc,has_func_multi_alloc_addr<AddressAlloc>::value>::multi_alloc_addr(
206+
alloc,std::min(count-i,maxMultiOps),outAddresses+i,bytes+i,alignment,hint ? (hint+i):nullptr);
207+
}
208+
189209
static inline void multi_free_addr(AddressAlloc& alloc, uint32_t count, const size_type* addr, const size_type* bytes) noexcept
190210
{
191211
for (uint32_t i=0; i<count; i+=maxMultiOps)
@@ -244,4 +264,4 @@ namespace nbl::core
244264

245265
}
246266

247-
#endif
267+
#endif

include/nbl/video/IGPUDescriptorSet.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,32 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
4545
uint32_t count;
4646
};
4747

48+
struct SDropDescriptorSet
49+
{
50+
IGPUDescriptorSet* dstSet;
51+
uint32_t binding;
52+
uint32_t arrayElement;
53+
uint32_t count;
54+
};
55+
4856
inline uint64_t getVersion() const { return m_version.load(); }
4957
inline IDescriptorPool* getPool() const { return m_pool.get(); }
5058
inline bool isZombie() const { return (m_pool.get() == nullptr); }
5159

60+
// why is this private? nothing it uses is private
61+
// small utility
62+
inline asset::IDescriptor::E_TYPE getBindingType(const uint32_t binding) const
63+
{
64+
for (auto t=0u; t<static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); t++)
65+
{
66+
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
67+
const auto& bindingRedirect = getLayout()->getDescriptorRedirect(type);
68+
if (bindingRedirect.getStorageOffset(redirect_t::binding_number_t{binding}).data!=redirect_t::Invalid)
69+
return type;
70+
}
71+
return asset::IDescriptor::E_TYPE::ET_COUNT;
72+
}
73+
5274
protected:
5375
IGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& _layout, core::smart_refctd_ptr<IDescriptorPool>&& pool, IDescriptorPool::SStorageOffsets&& offsets);
5476
virtual ~IGPUDescriptorSet();
@@ -61,6 +83,7 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
6183
void processWrite(const IGPUDescriptorSet::SWriteDescriptorSet& write, const asset::IDescriptor::E_TYPE type);
6284
bool validateCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy) const;
6385
void processCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy);
86+
void dropDescriptors(const IGPUDescriptorSet::SDropDescriptorSet& drop);
6487

6588
using redirect_t = IGPUDescriptorSetLayout::CBindingRedirect;
6689
// This assumes that descriptors of a particular type in the set will always be contiguous in pool's storage memory, regardless of which binding in the set they belong to.
@@ -76,18 +99,6 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
7699

77100
return descriptors+localOffset;
78101
}
79-
// small utility
80-
inline asset::IDescriptor::E_TYPE getBindingType(const uint32_t binding) const
81-
{
82-
for (auto t=0u; t<static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); t++)
83-
{
84-
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
85-
const auto& bindingRedirect = getLayout()->getDescriptorRedirect(type);
86-
if (bindingRedirect.getStorageOffset(redirect_t::binding_number_t{binding}).data!=redirect_t::Invalid)
87-
return type;
88-
}
89-
return asset::IDescriptor::E_TYPE::ET_COUNT;
90-
}
91102

92103
inline core::smart_refctd_ptr<IGPUSampler>* getMutableSamplers(const uint32_t binding) const
93104
{

include/nbl/video/ILogicalDevice.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
643643
return updateDescriptorSets({pDescriptorWrites,descriptorWriteCount},{pDescriptorCopies,descriptorCopyCount});
644644
}
645645

646+
// should this be joined together with the existing updateDescriptorSets?
647+
bool nullifyDescriptors(const std::span<const IGPUDescriptorSet::SDropDescriptorSet> dropDescriptors);
648+
646649
//! Renderpasses and Framebuffers
647650
core::smart_refctd_ptr<IGPURenderpass> createRenderpass(const IGPURenderpass::SCreationParams& params);
648651
inline core::smart_refctd_ptr<IGPUFramebuffer> createFramebuffer(IGPUFramebuffer::SCreationParams&& params)
@@ -865,6 +868,10 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
865868
};
866869
virtual void updateDescriptorSets_impl(const SUpdateDescriptorSetsParams& params) = 0;
867870

871+
// Drops refcounted references of the descriptors in these indices for the descriptor lifetime tracking
872+
// If the nullDescriptor device feature is enabled, this would also write a null descriptor to the descriptor set
873+
virtual void nullifyDescriptors_impl(const std::span<const IGPUDescriptorSet::SDropDescriptorSet> dropDescriptors) = 0;
874+
868875
virtual core::smart_refctd_ptr<IGPURenderpass> createRenderpass_impl(const IGPURenderpass::SCreationParams& params, IGPURenderpass::SCreationParamValidationResult&& validation) = 0;
869876
virtual core::smart_refctd_ptr<IGPUFramebuffer> createFramebuffer_impl(IGPUFramebuffer::SCreationParams&& params) = 0;
870877

0 commit comments

Comments
 (0)