Skip to content

Commit 1f5c721

Browse files
committed
More cleanups.
1 parent ed3948b commit 1f5c721

File tree

5 files changed

+175
-43
lines changed

5 files changed

+175
-43
lines changed

include/nbl/video/IGPUCommandBuffer.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ class NBL_API IGPUCommandBuffer :
130130

131131
inline const core::unordered_map<const IGPUDescriptorSet*, uint64_t>& getBoundDescriptorSetsRecord() const { return m_boundDescriptorSetsRecord; }
132132

133-
inline void clearBoundDescriptorSetsRecord() { m_boundDescriptorSetsRecord.clear(); }
134-
135133
protected:
136134
friend class IGPUQueue;
137135

@@ -247,7 +245,6 @@ class NBL_API IGPUCommandBuffer :
247245
virtual bool executeCommands_impl(uint32_t count, cmdbuf_t* const* const cmdbufs) = 0;
248246

249247
private:
250-
// Be wary of making it protected/calling it in the derived classes because it sets state which will overwrite the state set in base class methods.
251248
inline bool checkForParentPoolReset()
252249
{
253250
if (m_cmdpool->getResetCounter() <= m_resetCheckedStamp)
@@ -256,6 +253,8 @@ class NBL_API IGPUCommandBuffer :
256253
m_resetCheckedStamp = m_cmdpool->getResetCounter();
257254
m_state = ES_INITIAL;
258255

256+
m_boundDescriptorSetsRecord.clear();
257+
259258
m_commandList.head = nullptr;
260259
m_commandList.tail = nullptr;
261260

@@ -267,6 +266,7 @@ class NBL_API IGPUCommandBuffer :
267266
inline void releaseResourcesBackToPool()
268267
{
269268
deleteCommandList();
269+
m_boundDescriptorSetsRecord.clear();
270270
releaseResourcesBackToPool_impl();
271271
}
272272

@@ -277,6 +277,21 @@ class NBL_API IGPUCommandBuffer :
277277
m_commandList.tail = nullptr;
278278
}
279279

280+
inline bool checkStateBeforeRecording()
281+
{
282+
if (m_state != ES_RECORDING)
283+
{
284+
m_logger.log("Failed to record into command buffer: not in RECORDING state.", system::ILogger::ELL_ERROR);
285+
return false;
286+
}
287+
if (checkForParentPoolReset())
288+
{
289+
m_logger.log("Failed to record into command buffer: pool was reset since the recording begin() call.", system::ILogger::ELL_ERROR);
290+
return false;
291+
}
292+
return true;
293+
}
294+
280295
uint64_t m_resetCheckedStamp = 0;
281296

282297
// This bound descriptor set record doesn't include the descriptor sets whose layout has _any_ one of its bindings

include/nbl/video/IGPUCommandPool.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "nbl/video/decl/IBackendObject.h"
1010
#include "nbl/video/IGPUPipelineLayout.h"
1111

12-
#include "nbl/asset/ICPUCommandBuffer.h"
13-
1412
namespace nbl::video
1513
{
1614
class IGPUCommandBuffer;
@@ -104,20 +102,25 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
104102
public:
105103
static inline constexpr uint32_t STORAGE_SIZE = COMMAND_SEGMENT_SIZE - core::roundUp(sizeof(header_t), alignof(ICommand));
106104

107-
CCommandSegment()
105+
CCommandSegment(CCommandSegment* prev)
108106
{
109107
static_assert(alignof(ICommand) == COMMAND_SEGMENT_ALIGNMENT);
110108
m_header.commandAllocator = core::LinearAddressAllocator<uint32_t>(nullptr, 0u, 0u, alignof(ICommand), STORAGE_SIZE);
111109
m_header.next = nullptr;
112110

113111
wipeNextCommandSize();
112+
113+
if (prev)
114+
prev->m_header.next = this;
114115
}
115116

116117
~CCommandSegment()
117118
{
118-
auto* cmd = reinterpret_cast<ICommand*>(m_data);
119-
while ((cmd != segment_end()) || (cmd->getSize() != 0))
119+
for (ICommand* cmd = begin(); cmd != end();)
120120
{
121+
if (cmd->getSize() == 0)
122+
break;
123+
121124
auto* nextCmd = reinterpret_cast<ICommand*>(reinterpret_cast<uint8_t*>(cmd) + cmd->getSize());
122125
cmd->~ICommand();
123126
cmd = nextCmd;
@@ -142,7 +145,12 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
142145
inline CCommandSegment* getNextHead() const { return m_header.nextHead; }
143146
inline CCommandSegment* getPrevHead() const { return m_header.prevHead; }
144147

145-
inline ICommand* segment_end()
148+
inline ICommand* begin()
149+
{
150+
return reinterpret_cast<ICommand*>(m_data);
151+
}
152+
153+
inline ICommand* end()
146154
{
147155
return reinterpret_cast<ICommand*>(m_data + m_header.commandAllocator.get_allocated_size());
148156
}
@@ -255,6 +263,7 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
255263
if (!list.tail && !appendToList(list))
256264
return nullptr;
257265

266+
// not forwarding twice because newCmd() will never be called the second time
258267
auto newCmd = [&]() -> Cmd*
259268
{
260269
auto cmdMem = list.tail->allocate<Cmd>(args...);
@@ -290,12 +299,7 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
290299
if (head == m_head)
291300
m_head = head->getNextHead();
292301

293-
auto oneBefore = head->getPrevHead();
294-
auto oneAfter = head->getNextHead();
295-
CCommandSegment::linkHeads(oneBefore, oneAfter);
296-
297-
if (!oneBefore && !oneAfter)
298-
m_head = nullptr;
302+
CCommandSegment::linkHeads(head->getPrevHead(), head->getNextHead());
299303

300304
for (auto& segment = head; segment;)
301305
{
@@ -323,7 +327,7 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
323327
private:
324328
inline bool appendToList(SCommandSegmentList& list)
325329
{
326-
auto segment = m_pool.emplace<CCommandSegment>();
330+
auto segment = m_pool.emplace<CCommandSegment>(list.tail);
327331
if (!segment)
328332
{
329333
assert(false);
@@ -427,19 +431,19 @@ class IGPUCommandPool::CBeginRenderPassCmd : public IGPUCommandPool::IFixedSizeC
427431
class IGPUCommandPool::CPipelineBarrierCmd : public IGPUCommandPool::ICommand
428432
{
429433
public:
430-
CPipelineBarrierCmd(const uint32_t bufferCount, const asset::ICPUCommandBuffer::SBufferMemoryBarrier* bufferMemoryBarriers, const uint32_t imageCount, const asset::ICPUCommandBuffer::SImageMemoryBarrier* imageMemoryBarriers)
431-
: ICommand(calc_size(bufferCount, bufferMemoryBarriers, imageCount, imageMemoryBarriers)), m_resourceCount(bufferCount+imageCount)
434+
CPipelineBarrierCmd(const uint32_t bufferCount, const core::smart_refctd_ptr<const IGPUBuffer>* buffers, const uint32_t imageCount, const core::smart_refctd_ptr<const IGPUImage>* images)
435+
: ICommand(calc_size(bufferCount, buffers, imageCount, images)), m_resourceCount(bufferCount + imageCount)
432436
{
433437
auto barrierResources = getBarrierResources();
434438
std::uninitialized_default_construct_n(barrierResources, m_resourceCount);
435439

436440
uint32_t k = 0;
437441

438442
for (auto i = 0; i < bufferCount; ++i)
439-
barrierResources[k++] = bufferMemoryBarriers[i].buffer;
443+
barrierResources[k++] = buffers[i];
440444

441445
for (auto i = 0; i < imageCount; ++i)
442-
barrierResources[k++] = imageMemoryBarriers[i].image;
446+
barrierResources[k++] = images[i];
443447
}
444448

445449
~CPipelineBarrierCmd()
@@ -449,9 +453,9 @@ class IGPUCommandPool::CPipelineBarrierCmd : public IGPUCommandPool::ICommand
449453
barrierResources[i].~smart_refctd_ptr();
450454
}
451455

452-
static uint32_t calc_size(const uint32_t bufferCount, const asset::ICPUCommandBuffer::SBufferMemoryBarrier* bufferMemoryBarriers, const uint32_t imageCount, const asset::ICPUCommandBuffer::SImageMemoryBarrier* imageMemoryBarriers)
456+
static uint32_t calc_size(const uint32_t bufferCount, const core::smart_refctd_ptr<const IGPUBuffer>* buffers, const uint32_t imageCount, const core::smart_refctd_ptr<const IGPUImage>* images)
453457
{
454-
return core::alignUp(sizeof(CPipelineBarrierCmd) + (bufferCount+imageCount)*sizeof(core::smart_refctd_ptr<const core::IReferenceCounted>), alignof(CPipelineBarrierCmd));
458+
return core::alignUp(sizeof(CPipelineBarrierCmd) + (bufferCount + imageCount) * sizeof(core::smart_refctd_ptr<const core::IReferenceCounted>), alignof(CPipelineBarrierCmd));
455459
}
456460

457461
private:

include/nbl/video/IGPUQueue.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,6 @@ class NBL_API IGPUQueue : public core::Interface, public core::Unmovable
106106
return true;
107107
}
108108

109-
inline void clearBoundDescriptorSetsRecord(uint32_t _count, const SSubmitInfo* _submits)
110-
{
111-
for (uint32_t i = 0u; i < _count; ++i)
112-
{
113-
for (uint32_t c = 0u; c < _submits[i].commandBufferCount; ++c)
114-
{
115-
auto* cmdbuf = _submits[i].commandBuffers[c];
116-
if (cmdbuf)
117-
cmdbuf->clearBoundDescriptorSetsRecord();
118-
}
119-
}
120-
}
121-
122109
const uint32_t m_familyIndex;
123110
const E_CREATE_FLAGS m_flags;
124111
const float m_priority;

src/nbl/video/CVulkanQueue.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ bool CVulkanQueue::submit(uint32_t _count, const SSubmitInfo* _submits, IGPUFenc
108108
if(!IGPUQueue::markCommandBuffersAsDone(_count, _submits))
109109
return false;
110110

111-
IGPUQueue::clearBoundDescriptorSetsRecord(_count, _submits);
112-
113111
return true;
114112
}
115113

0 commit comments

Comments
 (0)