Skip to content

Commit b326ca7

Browse files
committed
Work on nullifying descriptors
1 parent d608e78 commit b326ca7

File tree

7 files changed

+62
-0
lines changed

7 files changed

+62
-0
lines changed

include/nbl/video/IGPUDescriptorSet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ 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); }
@@ -61,6 +69,7 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
6169
void processWrite(const IGPUDescriptorSet::SWriteDescriptorSet& write, const asset::IDescriptor::E_TYPE type);
6270
bool validateCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy) const;
6371
void processCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy);
72+
void dropDescriptors(const IGPUDescriptorSet::SDropDescriptorSet& drop);
6473

6574
using redirect_t = IGPUDescriptorSetLayout::CBindingRedirect;
6675
// 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.

include/nbl/video/ILogicalDevice.h

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

623+
// should this be joined together with the existing updateDescriptorSets?
624+
void nullifyDescriptors(const std::span<const IGPUDescriptorSet::SDropDescriptorSet> dropDescriptors);
625+
623626
//! Renderpasses and Framebuffers
624627
core::smart_refctd_ptr<IGPURenderpass> createRenderpass(const IGPURenderpass::SCreationParams& params);
625628
inline core::smart_refctd_ptr<IGPUFramebuffer> createFramebuffer(IGPUFramebuffer::SCreationParams&& params)
@@ -836,6 +839,10 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
836839
};
837840
virtual void updateDescriptorSets_impl(const SUpdateDescriptorSetsParams& params) = 0;
838841

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

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
285285
//
286286
// this needs to be done as a IGPUDescriptorSet::nullify(const uint32_t binding,
287287
// std::span<uint32_t> indices) function + a virtual nullify_impl
288+
video::IGPUDescriptorSet::SDropDescriptorSet dropDescriptorSet;
289+
dropDescriptorSet.dstSet = m_descriptorSet.get();
290+
dropDescriptorSet.binding = binding;
291+
dropDescriptorSet.arrayElement = i;
292+
dropDescriptorSet.count = 1;
293+
m_logicalDevice->nullifyDescriptors({ &dropDescriptorSet, 1 });
288294
}
289295
}
290296

src/nbl/video/CVulkanLogicalDevice.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,14 @@ void CVulkanLogicalDevice::updateDescriptorSets_impl(const SUpdateDescriptorSets
717717
m_devf.vk.vkUpdateDescriptorSets(m_vkdev,vk_writeDescriptorSets.size(),vk_writeDescriptorSets.data(),vk_copyDescriptorSets.size(),vk_copyDescriptorSets.data());
718718
}
719719

720+
void CVulkanLogicalDevice::nullifyDescriptors_impl(const std::span<const IGPUDescriptorSet::SDropDescriptorSet> dropDescriptors)
721+
{
722+
if (getEnabledFeatures().nullDescriptor)
723+
{
724+
// TODO: Write null descriptors here
725+
}
726+
}
727+
720728

721729
core::smart_refctd_ptr<IGPURenderpass> CVulkanLogicalDevice::createRenderpass_impl(const IGPURenderpass::SCreationParams& params, IGPURenderpass::SCreationParamValidationResult&& validation)
722730
{

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class CVulkanLogicalDevice final : public ILogicalDevice
281281
// descriptor sets
282282
core::smart_refctd_ptr<IDescriptorPool> createDescriptorPool_impl(const IDescriptorPool::SCreateInfo& createInfo) override;
283283
void updateDescriptorSets_impl(const SUpdateDescriptorSetsParams& params) override;
284+
void nullifyDescriptors_impl(const std::span<const IGPUDescriptorSet::SDropDescriptorSet> dropDescriptors) override;
284285

285286
// renderpasses and framebuffers
286287
core::smart_refctd_ptr<IGPURenderpass> createRenderpass_impl(const IGPURenderpass::SCreationParams& params, IGPURenderpass::SCreationParamValidationResult&& validation) override;

src/nbl/video/IGPUDescriptorSet.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ void IGPUDescriptorSet::processWrite(const IGPUDescriptorSet::SWriteDescriptorSe
124124
incrementVersion();
125125
}
126126

127+
void IGPUDescriptorSet::dropDescriptors(const IGPUDescriptorSet::SDropDescriptorSet& drop)
128+
{
129+
assert(drop.dstSet == this);
130+
131+
for (uint32_t t = 0; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
132+
{
133+
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
134+
135+
auto* dstDescriptors = drop.dstSet->getDescriptors(type, drop.binding);
136+
auto* dstSamplers = drop.dstSet->getMutableSamplers(drop.binding);
137+
138+
if (dstDescriptors)
139+
for (uint32_t i = 0; i < drop.count; i++)
140+
dstDescriptors[drop.arrayElement + i] = nullptr;
141+
142+
if (dstSamplers)
143+
for (uint32_t i = 0; i < drop.count; i++)
144+
dstSamplers[drop.arrayElement + i] = nullptr;
145+
}
146+
147+
incrementVersion();
148+
}
149+
127150
bool IGPUDescriptorSet::validateCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy) const
128151
{
129152
assert(copy.dstSet == this);

src/nbl/video/ILogicalDevice.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,14 @@ bool ILogicalDevice::updateDescriptorSets(const std::span<const IGPUDescriptorSe
420420
return true;
421421
}
422422

423+
void ILogicalDevice::nullifyDescriptors(const std::span<const IGPUDescriptorSet::SDropDescriptorSet> dropDescriptors)
424+
{
425+
for (const auto& drop : dropDescriptors)
426+
drop.dstSet->dropDescriptors(drop);
427+
428+
nullifyDescriptors_impl(dropDescriptors);
429+
}
430+
423431
core::smart_refctd_ptr<IGPURenderpass> ILogicalDevice::createRenderpass(const IGPURenderpass::SCreationParams& params)
424432
{
425433
IGPURenderpass::SCreationParamValidationResult validation = IGPURenderpass::validateCreationParams(params);

0 commit comments

Comments
 (0)