Skip to content

Commit afdee05

Browse files
author
devsh
committed
add IGPUCommandBuffer::empty()
1 parent fb7f033 commit afdee05

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

examples_tests

include/nbl/video/IGPUCommandBuffer.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
7878
return false;
7979
}
8080

81+
// This lets us know if not submitting this cmdbuf has no side-effects
82+
// TODO: should we track the `bind` and `set{$DynamicState}` commands?
83+
inline bool empty() const
84+
{
85+
switch (m_state)
86+
{
87+
case STATE::RECORDING:
88+
[[fallthrough]];
89+
case STATE::EXECUTABLE:
90+
[[fallthrough]];
91+
case STATE::PENDING:
92+
if (m_noCommands)
93+
return false;
94+
[[fallthrough]];
95+
default:
96+
return true;
97+
}
98+
}
99+
// if you use `getNativeHandle()` to record some custom commands between `begin()` and `end()`
100+
inline void setNotEmtpy() {m_noCommands = true;}
101+
81102
//! Begin, Reset, End
82103
enum class USAGE : uint8_t
83104
{
@@ -787,6 +808,7 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
787808

788809
uint64_t m_resetCheckedStamp;
789810
STATE m_state = STATE::INITIAL;
811+
bool m_noCommands = true;
790812
// only useful while recording
791813
SInheritanceInfo m_cachedInheritanceInfo;
792814
core::bitflag<USAGE> m_recordingFlags = USAGE::NONE;

src/nbl/video/IGPUCommandBuffer.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ bool IGPUCommandBuffer::begin(const core::bitflag<USAGE> flags, const SInheritan
149149
}
150150
else
151151
m_cachedInheritanceInfo = {};
152+
m_noCommands = true;
152153
return begin_impl(flags,inheritanceInfo);
153154
}
154155

@@ -239,6 +240,7 @@ bool IGPUCommandBuffer::setEvent(IEvent* _event, const SEventDependencyInfo& dep
239240
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CSetEventCmd>(m_commandList, core::smart_refctd_ptr<const IEvent>(_event)))
240241
return false;
241242

243+
m_noCommands = false;
242244
return setEvent_impl(_event,depInfo);
243245
}
244246

@@ -267,6 +269,7 @@ bool IGPUCommandBuffer::resetEvent(IEvent* _event, const core::bitflag<stage_fla
267269
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CResetEventCmd>(m_commandList,core::smart_refctd_ptr<const IEvent>(_event)))
268270
return false;
269271

272+
m_noCommands = false;
270273
return resetEvent_impl(_event,stageMask);
271274
}
272275

@@ -309,6 +312,7 @@ bool IGPUCommandBuffer::waitEvents(const std::span<IEvent*> events, const SEvent
309312
for (const auto& barrier : depInfo.imgBarriers)
310313
*(outIt++) = core::smart_refctd_ptr<const IGPUImage>(barrier.image);
311314
}
315+
m_noCommands = false;
312316
return waitEvents_impl(events,depInfos);
313317
}
314318

@@ -387,6 +391,7 @@ bool IGPUCommandBuffer::pipelineBarrier(const core::bitflag<asset::E_DEPENDENCY_
387391
*(outIt++) = barrier.range.buffer;
388392
for (const auto& barrier : depInfo.imgBarriers)
389393
*(outIt++) = core::smart_refctd_ptr<const IGPUImage>(barrier.image);
394+
m_noCommands = false;
390395
return pipelineBarrier_impl(dependencyFlags,depInfo);
391396
}
392397

@@ -404,6 +409,7 @@ bool IGPUCommandBuffer::fillBuffer(const asset::SBufferRange<IGPUBuffer>& range,
404409

405410
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CFillBufferCmd>(m_commandList,core::smart_refctd_ptr<const IGPUBuffer>(range.buffer)))
406411
return false;
412+
m_noCommands = false;
407413
return fillBuffer_impl(range,data);
408414
}
409415

@@ -425,6 +431,7 @@ bool IGPUCommandBuffer::updateBuffer(const asset::SBufferRange<IGPUBuffer>& rang
425431

426432
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CUpdateBufferCmd>(m_commandList,core::smart_refctd_ptr<const IGPUBuffer>(range.buffer)))
427433
return false;
434+
m_noCommands = false;
428435
return updateBuffer_impl(range,pData);
429436
}
430437

@@ -450,6 +457,7 @@ bool IGPUCommandBuffer::copyBuffer(const IGPUBuffer* const srcBuffer, IGPUBuffer
450457

451458
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyBufferCmd>(m_commandList,core::smart_refctd_ptr<const IGPUBuffer>(srcBuffer),core::smart_refctd_ptr<const IGPUBuffer>(dstBuffer)))
452459
return false;
460+
m_noCommands = false;
453461
return copyBuffer_impl(srcBuffer, dstBuffer, regionCount, pRegions);
454462
}
455463

@@ -467,6 +475,7 @@ bool IGPUCommandBuffer::clearColorImage(IGPUImage* const image, const IGPUImage:
467475

468476
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CClearColorImageCmd>(m_commandList,core::smart_refctd_ptr<const IGPUImage>(image)))
469477
return false;
478+
m_noCommands = false;
470479
return clearColorImage_impl(image, imageLayout, pColor, rangeCount, pRanges);
471480
}
472481

@@ -483,6 +492,7 @@ bool IGPUCommandBuffer::clearDepthStencilImage(IGPUImage* const image, const IGP
483492

484493
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CClearDepthStencilImageCmd>(m_commandList,core::smart_refctd_ptr<const IGPUImage>(image)))
485494
return false;
495+
m_noCommands = false;
486496
return clearDepthStencilImage_impl(image, imageLayout, pDepthStencil, rangeCount, pRanges);
487497
}
488498

@@ -503,6 +513,7 @@ bool IGPUCommandBuffer::copyBufferToImage(const IGPUBuffer* const srcBuffer, IGP
503513
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyBufferToImageCmd>(m_commandList, core::smart_refctd_ptr<const IGPUBuffer>(srcBuffer), core::smart_refctd_ptr<const IGPUImage>(dstImage)))
504514
return false;
505515

516+
m_noCommands = false;
506517
return copyBufferToImage_impl(srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
507518
}
508519

@@ -523,6 +534,7 @@ bool IGPUCommandBuffer::copyImageToBuffer(const IGPUImage* const srcImage, const
523534
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyImageToBufferCmd>(m_commandList, core::smart_refctd_ptr<const IGPUImage>(srcImage), core::smart_refctd_ptr<const IGPUBuffer>(dstBuffer)))
524535
return false;
525536

537+
m_noCommands = false;
526538
return copyImageToBuffer_impl(srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
527539
}
528540

@@ -552,6 +564,7 @@ bool IGPUCommandBuffer::copyImage(const IGPUImage* const srcImage, const IGPUIma
552564
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyImageCmd>(m_commandList, core::smart_refctd_ptr<const IGPUImage>(srcImage), core::smart_refctd_ptr<const IGPUImage>(dstImage)))
553565
return false;
554566

567+
m_noCommands = false;
555568
return copyImage_impl(srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
556569
}
557570

@@ -629,6 +642,7 @@ bool IGPUCommandBuffer::copyAccelerationStructure(const IGPUAccelerationStructur
629642
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyAccelerationStructureCmd>(m_commandList, core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.src), core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.dst)))
630643
return false;
631644

645+
m_noCommands = false;
632646
return copyAccelerationStructure_impl(copyInfo);
633647
}
634648

@@ -645,6 +659,7 @@ bool IGPUCommandBuffer::copyAccelerationStructureToMemory(const IGPUAcceleration
645659
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyAccelerationStructureToOrFromMemoryCmd>(m_commandList, core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.src), core::smart_refctd_ptr<const IGPUBuffer>(copyInfo.dst.buffer)))
646660
return false;
647661

662+
m_noCommands = false;
648663
return copyAccelerationStructureToMemory_impl(copyInfo);
649664
}
650665

@@ -661,6 +676,7 @@ bool IGPUCommandBuffer::copyAccelerationStructureFromMemory(const IGPUAccelerati
661676
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyAccelerationStructureToOrFromMemoryCmd>(m_commandList, core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.dst), core::smart_refctd_ptr<const IGPUBuffer>(copyInfo.src.buffer)))
662677
return false;
663678

679+
m_noCommands = false;
664680
return copyAccelerationStructureFromMemory_impl(copyInfo);
665681
}
666682

@@ -676,6 +692,7 @@ bool IGPUCommandBuffer::bindComputePipeline(const IGPUComputePipeline* const pip
676692
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBindComputePipelineCmd>(m_commandList, core::smart_refctd_ptr<const IGPUComputePipeline>(pipeline)))
677693
return false;
678694

695+
m_noCommands = false;
679696
bindComputePipeline_impl(pipeline);
680697

681698
return true;
@@ -695,6 +712,7 @@ bool IGPUCommandBuffer::bindGraphicsPipeline(const IGPUGraphicsPipeline* const p
695712
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBindGraphicsPipelineCmd>(m_commandList, core::smart_refctd_ptr<const IGPUGraphicsPipeline>(pipeline)))
696713
return false;
697714

715+
m_noCommands = false;
698716
return bindGraphicsPipeline_impl(pipeline);
699717
}
700718

@@ -752,6 +770,7 @@ bool IGPUCommandBuffer::bindDescriptorSets(
752770
m_boundDescriptorSetsRecord.insert({ pDescriptorSets[i], currentVersion });
753771
}
754772

773+
m_noCommands = false;
755774
return bindDescriptorSets_impl(pipelineBindPoint, layout, firstSet, descriptorSetCount, pDescriptorSets, dynamicOffsetCount, dynamicOffsets);
756775
}
757776

@@ -766,6 +785,7 @@ bool IGPUCommandBuffer::pushConstants(const IGPUPipelineLayout* const layout, co
766785
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CPushConstantsCmd>(m_commandList, core::smart_refctd_ptr<const IGPUPipelineLayout>(layout)))
767786
return false;
768787

788+
m_noCommands = false;
769789
return pushConstants_impl(layout, stageFlags, offset, size, pValues);
770790
}
771791

@@ -783,6 +803,7 @@ bool IGPUCommandBuffer::bindVertexBuffers(const uint32_t firstBinding, const uin
783803
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBindVertexBuffersCmd>(m_commandList,bindingCount,pBindings))
784804
return false;
785805

806+
m_noCommands = false;
786807
return bindVertexBuffers_impl(firstBinding, bindingCount, pBindings);
787808
}
788809

@@ -812,6 +833,7 @@ bool IGPUCommandBuffer::bindIndexBuffer(const asset::SBufferBinding<const IGPUBu
812833
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBindIndexBufferCmd>(m_commandList, core::smart_refctd_ptr<const IGPUBuffer>(binding.buffer)))
813834
return false;
814835

836+
m_noCommands = false;
815837
return bindIndexBuffer_impl(binding,indexType);
816838
}
817839

@@ -845,6 +867,7 @@ bool IGPUCommandBuffer::setLineWidth(const float width)
845867
else if (width!=1.f)
846868
return false;
847869

870+
m_noCommands = false;
848871
return setLineWidth_impl(width);
849872
}
850873

@@ -859,6 +882,7 @@ bool IGPUCommandBuffer::setDepthBounds(const float minDepthBounds, const float m
859882
if (minDepthBounds<0.f || maxDepthBounds>1.f)
860883
return false;
861884

885+
m_noCommands = false;
862886
return setDepthBounds_impl(minDepthBounds,maxDepthBounds);
863887
}
864888

@@ -875,6 +899,7 @@ bool IGPUCommandBuffer::resetQueryPool(IQueryPool* const queryPool, const uint32
875899
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CResetQueryPoolCmd>(m_commandList, core::smart_refctd_ptr<const IQueryPool>(queryPool)))
876900
return false;
877901

902+
m_noCommands = false;
878903
return resetQueryPool_impl(queryPool, firstQuery, queryCount);
879904
}
880905

@@ -890,6 +915,7 @@ bool IGPUCommandBuffer::beginQuery(IQueryPool* const queryPool, const uint32_t q
890915
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBeginQueryCmd>(m_commandList, core::smart_refctd_ptr<const IQueryPool>(queryPool)))
891916
return false;
892917

918+
m_noCommands = false;
893919
return beginQuery_impl(queryPool, query, flags);
894920
}
895921

@@ -905,6 +931,7 @@ bool IGPUCommandBuffer::endQuery(IQueryPool* const queryPool, const uint32_t que
905931
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CEndQueryCmd>(m_commandList, core::smart_refctd_ptr<const IQueryPool>(queryPool)))
906932
return false;
907933

934+
m_noCommands = false;
908935
return endQuery_impl(queryPool, query);
909936
}
910937

@@ -925,6 +952,7 @@ bool IGPUCommandBuffer::writeTimestamp(const stage_flags_t pipelineStage, IQuery
925952
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CWriteTimestampCmd>(m_commandList, core::smart_refctd_ptr<const IQueryPool>(queryPool)))
926953
return false;
927954

955+
m_noCommands = false;
928956
return writeTimestamp_impl(pipelineStage, queryPool, query);
929957
}
930958

@@ -947,6 +975,7 @@ bool IGPUCommandBuffer::writeAccelerationStructureProperties(const std::span<con
947975
auto oit = cmd->getVariableCountResources();
948976
for (auto& as : pAccelerationStructures)
949977
*(oit++) = core::smart_refctd_ptr<const core::IReferenceCounted>(as);
978+
m_noCommands = false;
950979
return writeAccelerationStructureProperties_impl(pAccelerationStructures, queryType, queryPool, firstQuery);
951980
}
952981

@@ -968,6 +997,7 @@ bool IGPUCommandBuffer::copyQueryPoolResults(
968997
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CCopyQueryPoolResultsCmd>(m_commandList, core::smart_refctd_ptr<const IQueryPool>(queryPool), core::smart_refctd_ptr<const IGPUBuffer>(dstBuffer.buffer)))
969998
return false;
970999

1000+
m_noCommands = false;
9711001
return copyQueryPoolResults_impl(queryPool, firstQuery, queryCount, dstBuffer, stride, flags);
9721002
}
9731003

@@ -984,6 +1014,7 @@ bool IGPUCommandBuffer::dispatch(const uint32_t groupCountX, const uint32_t grou
9841014
if (groupCountX>limits.maxComputeWorkGroupCount[0] || groupCountY>limits.maxComputeWorkGroupCount[1] || groupCountZ>limits.maxComputeWorkGroupCount[2])
9851015
return false;
9861016

1017+
m_noCommands = false;
9871018
return dispatch_impl(groupCountX,groupCountY,groupCountZ);
9881019
}
9891020

@@ -998,6 +1029,7 @@ bool IGPUCommandBuffer::dispatchIndirect(const asset::SBufferBinding<const IGPUB
9981029
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CIndirectCmd>(m_commandList,core::smart_refctd_ptr<const IGPUBuffer>(binding.buffer)))
9991030
return false;
10001031

1032+
m_noCommands = false;
10011033
return dispatchIndirect_impl(binding);
10021034
}
10031035

@@ -1037,6 +1069,7 @@ bool IGPUCommandBuffer::beginRenderPass(SRenderpassBeginInfo info, const SUBPASS
10371069
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBeginRenderPassCmd>(m_commandList,core::smart_refctd_ptr<const IGPURenderpass>(info.renderpass),core::smart_refctd_ptr<const IGPUFramebuffer>(info.framebuffer)))
10381070
return false;
10391071

1072+
m_noCommands = false;
10401073
if (!beginRenderPass_impl(info,contents))
10411074
return false;
10421075
m_cachedInheritanceInfo.renderpass = info.renderpass;
@@ -1054,6 +1087,7 @@ bool IGPUCommandBuffer::nextSubpass(const SUBPASS_CONTENTS contents)
10541087
return false;
10551088

10561089
m_cachedInheritanceInfo.subpass++;
1090+
m_noCommands = false;
10571091
return nextSubpass_impl(contents);
10581092
}
10591093

@@ -1066,6 +1100,7 @@ bool IGPUCommandBuffer::endRenderPass()
10661100
return false;
10671101

10681102
m_cachedInheritanceInfo.subpass = SInheritanceInfo{}.subpass;
1103+
m_noCommands = false;
10691104
return endRenderPass_impl();
10701105
}
10711106

@@ -1109,6 +1144,7 @@ bool IGPUCommandBuffer::clearAttachments(const SClearAttachments& info)
11091144
return false;
11101145
}
11111146

1147+
m_noCommands = false;
11121148
return clearAttachments_impl(info);
11131149
}
11141150

@@ -1121,6 +1157,7 @@ bool IGPUCommandBuffer::draw(const uint32_t vertexCount, const uint32_t instance
11211157
if (vertexCount==0u || instanceCount == 0u)
11221158
return false;
11231159

1160+
m_noCommands = false;
11241161
return draw_impl(vertexCount,instanceCount,firstVertex,firstInstance);
11251162
}
11261163

@@ -1132,6 +1169,7 @@ bool IGPUCommandBuffer::drawIndexed(const uint32_t indexCount, const uint32_t in
11321169
if (indexCount==0u || instanceCount == 0u)
11331170
return false;
11341171

1172+
m_noCommands = false;
11351173
return drawIndexed_impl(indexCount,instanceCount,firstIndex,vertexOffset,firstInstance);
11361174
}
11371175

@@ -1181,6 +1219,7 @@ bool IGPUCommandBuffer::drawIndirect(const asset::SBufferBinding<const IGPUBuffe
11811219
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CIndirectCmd>(m_commandList,core::smart_refctd_ptr<const IGPUBuffer>(binding.buffer)))
11821220
return false;
11831221

1222+
m_noCommands = false;
11841223
return drawIndirect_impl(binding, drawCount, stride);
11851224
}
11861225

@@ -1192,6 +1231,7 @@ bool IGPUCommandBuffer::drawIndexedIndirect(const asset::SBufferBinding<const IG
11921231
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CIndirectCmd>(m_commandList, core::smart_refctd_ptr<const IGPUBuffer>(binding.buffer)))
11931232
return false;
11941233

1234+
m_noCommands = false;
11951235
return drawIndexedIndirect_impl(binding, drawCount, stride);
11961236
}
11971237

@@ -1203,6 +1243,7 @@ bool IGPUCommandBuffer::drawIndirectCount(const asset::SBufferBinding<const IGPU
12031243
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CDrawIndirectCountCmd>(m_commandList, core::smart_refctd_ptr<const IGPUBuffer>(indirectBinding.buffer), core::smart_refctd_ptr<const IGPUBuffer>(countBinding.buffer)))
12041244
return false;
12051245

1246+
m_noCommands = false;
12061247
return drawIndirectCount_impl(indirectBinding, countBinding, maxDrawCount, stride);
12071248
}
12081249

@@ -1214,6 +1255,7 @@ bool IGPUCommandBuffer::drawIndexedIndirectCount(const asset::SBufferBinding<con
12141255
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CDrawIndirectCountCmd>(m_commandList, core::smart_refctd_ptr<const IGPUBuffer>(indirectBinding.buffer), core::smart_refctd_ptr<const IGPUBuffer>(countBinding.buffer)))
12151256
return false;
12161257

1258+
m_noCommands = false;
12171259
return drawIndexedIndirectCount_impl(indirectBinding, countBinding, maxDrawCount, stride);
12181260
}
12191261

@@ -1307,6 +1349,7 @@ bool IGPUCommandBuffer::blitImage(const IGPUImage* const srcImage, const IGPUIma
13071349
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CBlitImageCmd>(m_commandList, core::smart_refctd_ptr<const IGPUImage>(srcImage), core::smart_refctd_ptr<const IGPUImage>(dstImage)))
13081350
return false;
13091351

1352+
m_noCommands = false;
13101353
return blitImage_impl(srcImage, srcImageLayout, dstImage, dstImageLayout, regions, filter);
13111354
}
13121355

@@ -1340,6 +1383,7 @@ bool IGPUCommandBuffer::resolveImage(const IGPUImage* const srcImage, const IGPU
13401383
if (!m_cmdpool->m_commandListPool.emplace<IGPUCommandPool::CResolveImageCmd>(m_commandList, core::smart_refctd_ptr<const IGPUImage>(srcImage), core::smart_refctd_ptr<const IGPUImage>(dstImage)))
13411384
return false;
13421385

1386+
m_noCommands = false;
13431387
return resolveImage_impl(srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
13441388
}
13451389

@@ -1362,6 +1406,7 @@ bool IGPUCommandBuffer::executeCommands(const uint32_t count, IGPUCommandBuffer*
13621406
return false;
13631407
for (auto i=0u; i<count; i++)
13641408
cmd->getVariableCountResources()[i] = core::smart_refctd_ptr<const core::IReferenceCounted>(cmdbufs[i]);
1409+
m_noCommands = false;
13651410
return executeCommands_impl(count,cmdbufs);
13661411
}
13671412

0 commit comments

Comments
 (0)