9
9
#include " nbl/video/decl/IBackendObject.h"
10
10
#include " nbl/video/IGPUPipelineLayout.h"
11
11
12
- #include " nbl/asset/ICPUCommandBuffer.h"
13
-
14
12
namespace nbl ::video
15
13
{
16
14
class IGPUCommandBuffer ;
@@ -104,20 +102,25 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
104
102
public:
105
103
static inline constexpr uint32_t STORAGE_SIZE = COMMAND_SEGMENT_SIZE - core::roundUp (sizeof (header_t ), alignof (ICommand));
106
104
107
- CCommandSegment ()
105
+ CCommandSegment (CCommandSegment* prev )
108
106
{
109
107
static_assert (alignof (ICommand) == COMMAND_SEGMENT_ALIGNMENT);
110
108
m_header.commandAllocator = core::LinearAddressAllocator<uint32_t >(nullptr , 0u , 0u , alignof (ICommand), STORAGE_SIZE);
111
109
m_header.next = nullptr ;
112
110
113
111
wipeNextCommandSize ();
112
+
113
+ if (prev)
114
+ prev->m_header .next = this ;
114
115
}
115
116
116
117
~CCommandSegment ()
117
118
{
118
- auto * cmd = reinterpret_cast <ICommand*>(m_data);
119
- while ((cmd != segment_end ()) || (cmd->getSize () != 0 ))
119
+ for (ICommand* cmd = begin (); cmd != end ();)
120
120
{
121
+ if (cmd->getSize () == 0 )
122
+ break ;
123
+
121
124
auto * nextCmd = reinterpret_cast <ICommand*>(reinterpret_cast <uint8_t *>(cmd) + cmd->getSize ());
122
125
cmd->~ICommand ();
123
126
cmd = nextCmd;
@@ -142,7 +145,12 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
142
145
inline CCommandSegment* getNextHead () const { return m_header.nextHead ; }
143
146
inline CCommandSegment* getPrevHead () const { return m_header.prevHead ; }
144
147
145
- inline ICommand* segment_end ()
148
+ inline ICommand* begin ()
149
+ {
150
+ return reinterpret_cast <ICommand*>(m_data);
151
+ }
152
+
153
+ inline ICommand* end ()
146
154
{
147
155
return reinterpret_cast <ICommand*>(m_data + m_header.commandAllocator .get_allocated_size ());
148
156
}
@@ -255,6 +263,7 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
255
263
if (!list.tail && !appendToList (list))
256
264
return nullptr ;
257
265
266
+ // not forwarding twice because newCmd() will never be called the second time
258
267
auto newCmd = [&]() -> Cmd*
259
268
{
260
269
auto cmdMem = list.tail ->allocate <Cmd>(args...);
@@ -290,12 +299,7 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
290
299
if (head == m_head)
291
300
m_head = head->getNextHead ();
292
301
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 ());
299
303
300
304
for (auto & segment = head; segment;)
301
305
{
@@ -323,7 +327,7 @@ class NBL_API IGPUCommandPool : public core::IReferenceCounted, public IBackendO
323
327
private:
324
328
inline bool appendToList (SCommandSegmentList& list)
325
329
{
326
- auto segment = m_pool.emplace <CCommandSegment>();
330
+ auto segment = m_pool.emplace <CCommandSegment>(list. tail );
327
331
if (!segment)
328
332
{
329
333
assert (false );
@@ -427,19 +431,19 @@ class IGPUCommandPool::CBeginRenderPassCmd : public IGPUCommandPool::IFixedSizeC
427
431
class IGPUCommandPool ::CPipelineBarrierCmd : public IGPUCommandPool::ICommand
428
432
{
429
433
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)
432
436
{
433
437
auto barrierResources = getBarrierResources ();
434
438
std::uninitialized_default_construct_n (barrierResources, m_resourceCount);
435
439
436
440
uint32_t k = 0 ;
437
441
438
442
for (auto i = 0 ; i < bufferCount; ++i)
439
- barrierResources[k++] = bufferMemoryBarriers [i]. buffer ;
443
+ barrierResources[k++] = buffers [i];
440
444
441
445
for (auto i = 0 ; i < imageCount; ++i)
442
- barrierResources[k++] = imageMemoryBarriers [i]. image ;
446
+ barrierResources[k++] = images [i];
443
447
}
444
448
445
449
~CPipelineBarrierCmd ()
@@ -449,9 +453,9 @@ class IGPUCommandPool::CPipelineBarrierCmd : public IGPUCommandPool::ICommand
449
453
barrierResources[i].~smart_refctd_ptr ();
450
454
}
451
455
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 )
453
457
{
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));
455
459
}
456
460
457
461
private:
0 commit comments