Skip to content

Commit 2275fb0

Browse files
committed
Fix some bugs and do some cleanups.
1 parent ba81628 commit 2275fb0

File tree

9 files changed

+192
-132
lines changed

9 files changed

+192
-132
lines changed

include/nbl/core/alloc/IteratablePoolAddressAllocator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ template<typename _size_type>
2222
class IteratablePoolAddressAllocator : protected PoolAddressAllocator<_size_type>
2323
{
2424
using Base = PoolAddressAllocator<_size_type>;
25-
public:
26-
inline _size_type* begin() { return &Base::getFreeStack(Base::freeStackCtr); }
2725
protected:
26+
inline _size_type* begin() { return &Base::getFreeStack(Base::freeStackCtr); }
2827
inline _size_type& getIteratorOffset(_size_type i) {return reinterpret_cast<_size_type*>(Base::reservedSpace)[Base::blockCount+i];}
2928
inline const _size_type& getIteratorOffset(_size_type i) const {return reinterpret_cast<const _size_type*>(Base::reservedSpace)[Base::blockCount+i];}
3029

include/nbl/video/IDescriptorPool.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,30 @@ class IDescriptorPool : public core::IReferenceCounted, public IBackendObject
3737
uint32_t maxDescriptorCount[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT)] = { 0 };
3838
};
3939

40-
struct SDescriptorOffsets
40+
struct SStorageOffsets
4141
{
42-
SDescriptorOffsets()
42+
static constexpr inline uint32_t Invalid = ~0u;
43+
44+
SStorageOffsets()
45+
{
46+
// The default constructor should initiailze all the offsets to Invalid because other parts of the codebase relies on it to
47+
// know which descriptors are present in the set and hence should be destroyed, or which set in the pool is non-zombie.
48+
std::fill_n(data, static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT) + 2, Invalid);
49+
}
50+
51+
inline uint32_t getDescriptorOffset(const asset::IDescriptor::E_TYPE type) const
4352
{
44-
// The default constructor should initiailze all the offsets to an invalid value (~0u) because ~IGPUDescriptorSet relies on it to
45-
// know which descriptors are present in the set and hence should be destroyed.
46-
std::fill_n(data, static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT) + 1, ~0u);
53+
const uint32_t idx = static_cast<uint32_t>(type);
54+
assert(idx < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT));
55+
return data[idx];
4756
}
4857

49-
uint32_t data[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT) + 1];
58+
inline uint32_t getMutableSamplerOffset() const { return data[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT)]; }
59+
60+
inline uint32_t getSetOffset() const { return data[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT) + 1]; }
61+
inline uint32_t& getSetOffset() { return data[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT) + 1]; }
62+
63+
uint32_t data[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT) + 2];
5064
};
5165

5266
inline core::smart_refctd_ptr<IGPUDescriptorSet> createDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& layout)
@@ -103,7 +117,7 @@ class IDescriptorPool : public core::IReferenceCounted, public IBackendObject
103117
}
104118
}
105119

106-
virtual bool createDescriptorSets_impl(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, SDescriptorOffsets* const offsets, const uint32_t firstSetOffsetInPool, core::smart_refctd_ptr<IGPUDescriptorSet>* output) = 0;
120+
virtual bool createDescriptorSets_impl(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, SStorageOffsets* const offsets, core::smart_refctd_ptr<IGPUDescriptorSet>* output) = 0;
107121

108122
virtual bool reset_impl() = 0;
109123

@@ -159,10 +173,10 @@ class IDescriptorPool : public core::IReferenceCounted, public IBackendObject
159173
friend class IGPUDescriptorSet;
160174
// Returns the offset into the pool's descriptor storage. These offsets will be combined
161175
// later with base memory addresses to get the actual memory address where we put the core::smart_refctd_ptr<const IDescriptor>.
162-
bool allocateDescriptorOffsets(SDescriptorOffsets& offsets, const IGPUDescriptorSetLayout* layout);
163-
void freeDescriptorOffsets(SDescriptorOffsets& offsets, const IGPUDescriptorSetLayout* layout);
176+
bool allocateStorageOffsets(SStorageOffsets& offsets, const IGPUDescriptorSetLayout* layout);
177+
void rewindLastStorageAllocations(const uint32_t count, const SStorageOffsets* offsets, const IGPUDescriptorSetLayout *const *const layouts);
164178

165-
void deleteSetStorage(IGPUDescriptorSet* set);
179+
void deleteSetStorage(IGPUDescriptorSet*& set);
166180

167181
struct allocator_state_t
168182
{

include/nbl/video/IGPUDescriptorSet.h

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -57,53 +57,15 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
5757
inline bool isZombie() const { return (m_pool.get() == nullptr); }
5858

5959
protected:
60-
IGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& _layout, core::smart_refctd_ptr<IDescriptorPool>&& pool, const uint32_t poolOffset, IDescriptorPool::SDescriptorOffsets&& offsets);
60+
IGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& _layout, core::smart_refctd_ptr<IDescriptorPool>&& pool, IDescriptorPool::SStorageOffsets&& offsets);
6161
virtual ~IGPUDescriptorSet();
6262

6363
private:
64-
friend class ILogicalDevice;
65-
6664
inline void incrementVersion() { m_version.fetch_add(1ull); }
6765

68-
// TODO(achal): Don't know yet if we want to keep these.
69-
inline void processWrite(const IGPUDescriptorSet::SWriteDescriptorSet& write)
70-
{
71-
assert(write.dstSet == this);
72-
73-
auto* descriptors = getDescriptors(write.descriptorType, write.binding);
74-
auto* samplers = getMutableSamplers(write.binding);
75-
for (auto j = 0; j < write.count; ++j)
76-
{
77-
descriptors[j] = write.info[j].desc;
78-
79-
if (samplers)
80-
samplers[j] = write.info[j].info.image.sampler;
81-
}
82-
}
83-
84-
#if 0
85-
inline void processCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy)
86-
{
87-
assert(copy.dstSet == this);
88-
89-
for (uint32_t t = 0; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
90-
{
91-
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
92-
93-
auto* srcDescriptors = srcDS->getDescriptors(type, pDescriptorCopies[i].srcBinding);
94-
auto* srcSamplers = srcDS->getMutableSamplers(pDescriptorCopies[i].srcBinding);
95-
96-
auto* dstDescriptors = dstDS->getDescriptors(type, pDescriptorCopies[i].dstBinding);
97-
auto* dstSamplers = dstDS->getMutableSamplers(pDescriptorCopies[i].dstBinding);
98-
99-
if (srcDescriptors && dstDescriptors)
100-
std::copy_n(srcDescriptors, pDescriptorCopies[i].count, dstDescriptors);
101-
102-
if (srcSamplers && dstSamplers)
103-
std::copy_n(srcSamplers, pDescriptorCopies[i].count, dstSamplers);
104-
}
105-
}
106-
#endif
66+
friend class ILogicalDevice;
67+
bool processWrite(const IGPUDescriptorSet::SWriteDescriptorSet& write);
68+
bool processCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy);
10769

10870
// 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.
10971
inline core::smart_refctd_ptr<asset::IDescriptor>* getDescriptors(const asset::IDescriptor::E_TYPE type, const uint32_t binding) const
@@ -138,7 +100,7 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
138100
if (baseAddress == nullptr)
139101
return nullptr;
140102

141-
const auto offset = getDescriptorStorageOffset(type);
103+
const auto offset = m_storageOffsets.getDescriptorOffset(type);
142104
if (offset == ~0u)
143105
return nullptr;
144106

@@ -151,21 +113,17 @@ class IGPUDescriptorSet : public asset::IDescriptorSet<const IGPUDescriptorSetLa
151113
if (baseAddress == nullptr)
152114
return nullptr;
153115

154-
const auto poolOffset = getMutableSamplerStorageOffset();
155-
if (poolOffset == ~0u)
116+
const auto offset = m_storageOffsets.getMutableSamplerOffset();
117+
if (offset == ~0u)
156118
return nullptr;
157119

158-
return baseAddress + poolOffset;
120+
return baseAddress + offset;
159121
}
160122

161-
inline uint32_t getDescriptorStorageOffset(const asset::IDescriptor::E_TYPE type) const { return m_descriptorStorageOffsets.data[static_cast<uint32_t>(type)]; }
162-
inline uint32_t getMutableSamplerStorageOffset() const { return m_descriptorStorageOffsets.data[static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT)]; }
163-
164123
std::atomic_uint64_t m_version;
165124
friend class IDescriptorPool;
166125
core::smart_refctd_ptr<IDescriptorPool> m_pool;
167-
uint32_t m_poolOffset;
168-
const IDescriptorPool::SDescriptorOffsets m_descriptorStorageOffsets;
126+
const IDescriptorPool::SStorageOffsets m_storageOffsets;
169127
};
170128

171129
}

src/nbl/video/CVulkanDescriptorPool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void CVulkanDescriptorPool::setObjectDebugName(const char* label) const
2626
vkSetDebugUtilsObjectNameEXT(vulkanDevice->getInternalObject(), &nameInfo);
2727
}
2828

29-
bool CVulkanDescriptorPool::createDescriptorSets_impl(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, SDescriptorOffsets* const offsets, const uint32_t firstSetOffsetInPool, core::smart_refctd_ptr<IGPUDescriptorSet>* output)
29+
bool CVulkanDescriptorPool::createDescriptorSets_impl(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, SStorageOffsets* const offsets, core::smart_refctd_ptr<IGPUDescriptorSet>* output)
3030
{
3131
VkDescriptorSetAllocateInfo vk_allocateInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO };
3232
vk_allocateInfo.pNext = nullptr; // pNext must be NULL or a pointer to a valid instance of VkDescriptorSetVariableDescriptorCountAllocateInfo
@@ -50,7 +50,7 @@ bool CVulkanDescriptorPool::createDescriptorSets_impl(uint32_t count, const IGPU
5050
if (vk->vk.vkAllocateDescriptorSets(vulkanDevice->getInternalObject(), &vk_allocateInfo, vk_descriptorSets.data()) == VK_SUCCESS)
5151
{
5252
for (uint32_t i = 0; i < count; ++i)
53-
output[i] = core::make_smart_refctd_ptr<CVulkanDescriptorSet>(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(layouts[i]), core::smart_refctd_ptr<IDescriptorPool>(this), firstSetOffsetInPool + i, std::move(offsets[i]), vk_descriptorSets[i]);
53+
output[i] = core::make_smart_refctd_ptr<CVulkanDescriptorSet>(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>(layouts[i]), core::smart_refctd_ptr<IDescriptorPool>(this), std::move(offsets[i]), vk_descriptorSets[i]);
5454

5555
return true;
5656
}

src/nbl/video/CVulkanDescriptorPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CVulkanDescriptorPool : public IDescriptorPool
2323
void setObjectDebugName(const char* label) const override;
2424

2525
private:
26-
bool createDescriptorSets_impl(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, SDescriptorOffsets *const offsets, const uint32_t firstSetOffsetInPool, core::smart_refctd_ptr<IGPUDescriptorSet>* output) override;
26+
bool createDescriptorSets_impl(uint32_t count, const IGPUDescriptorSetLayout* const* layouts, SStorageOffsets *const offsets, core::smart_refctd_ptr<IGPUDescriptorSet>* output) override;
2727
bool reset_impl() override;
2828

2929
VkDescriptorPool m_descriptorPool;

src/nbl/video/CVulkanDescriptorSet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class CVulkanDescriptorPool;
1313
class CVulkanDescriptorSet : public IGPUDescriptorSet
1414
{
1515
public:
16-
CVulkanDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& layout, core::smart_refctd_ptr<IDescriptorPool>&& pool, const uint32_t poolOffset, IDescriptorPool::SDescriptorOffsets offsets, VkDescriptorSet descriptorSet)
17-
: IGPUDescriptorSet(std::move(layout), std::move(pool), poolOffset, std::move(offsets)), m_descriptorSet(descriptorSet)
16+
CVulkanDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& layout, core::smart_refctd_ptr<IDescriptorPool>&& pool, IDescriptorPool::SStorageOffsets offsets, VkDescriptorSet descriptorSet)
17+
: IGPUDescriptorSet(std::move(layout), std::move(pool), std::move(offsets)), m_descriptorSet(descriptorSet)
1818
{}
1919

2020
~CVulkanDescriptorSet();

0 commit comments

Comments
 (0)