Skip to content

Commit 82e3ae1

Browse files
handle when we have more than 128kb of command data to track
1 parent f543598 commit 82e3ae1

5 files changed

Lines changed: 283 additions & 108 deletions

File tree

include/nbl/video/IGPUAccelerationStructure.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ class IGPUBottomLevelAccelerationStructure : public asset::IBottomLevelAccelerat
289289
totalPrims += buildRangeInfo.primitiveCount;
290290
return true;
291291
}
292-
293-
inline core::smart_refctd_ptr<const IReferenceCounted>* fillTracking(core::smart_refctd_ptr<const IReferenceCounted>* oit) const
292+
293+
template<typename ForwardIterator> // TODO: requires
294+
inline ForwardIterator fillTracking(ForwardIterator oit) const
294295
{
295296
*(oit++) = core::smart_refctd_ptr<const IReferenceCounted>(Base::scratch.buffer);
296297
if (Base::isUpdate)
@@ -486,7 +487,8 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
486487
return retval;
487488
}
488489

489-
inline core::smart_refctd_ptr<const IReferenceCounted>* fillTracking(core::smart_refctd_ptr<const IReferenceCounted>* oit) const
490+
template<typename ForwardIterator> // TODO: requires
491+
inline ForwardIterator fillTracking(ForwardIterator oit) const
490492
{
491493
*(oit++) = core::smart_refctd_ptr<const IReferenceCounted>(Base::scratch.buffer);
492494
if (Base::isUpdate)
@@ -713,8 +715,8 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
713715
*(tracked++) = *(it++);
714716
}
715717
// Useful if TLAS got built externally as well
716-
template<typename Iterator>
717-
inline void insertTrackedBLASes(const Iterator begin, const Iterator end, const build_ver_t buildVer)
718+
template<typename ForwardIterator>
719+
inline void insertTrackedBLASes(ForwardIterator begin, const uint32_t count, const build_ver_t buildVer)
718720
{
719721
if (buildVer==0)
720722
return;
@@ -725,14 +727,19 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
725727
for (auto it=std::next(prev); it!=m_pendingBuilds.end()&&it->ordinal>buildVer; prev=it++) {}
726728
auto inserted = m_pendingBuilds.emplace_after(prev);
727729
// now fill the contents
728-
inserted->BLASes.insert(begin,end);
730+
inserted->BLASes.reserve(count);
731+
for (auto i=0u; i<count; i++)
732+
{
733+
inserted->BLASes.insert(*begin);
734+
++begin;
735+
}
729736
inserted->ordinal = buildVer;
730737
}
731-
template<typename Iterator>
732-
inline build_ver_t pushTrackedBLASes(const Iterator begin, const Iterator end)
738+
template<typename ForwardIterator>
739+
inline build_ver_t pushTrackedBLASes(const ForwardIterator begin, const uint32_t count)
733740
{
734741
const auto buildVer = registerNextBuildVer();
735-
insertTrackedBLASes<Iterator>(begin,end,buildVer);
742+
insertTrackedBLASes<ForwardIterator>(begin,count,buildVer);
736743
return buildVer;
737744
}
738745
// a little utility to make sure nothing from before this build version gets tracked
@@ -750,18 +757,9 @@ class IGPUTopLevelAccelerationStructure : public asset::ITopLevelAccelerationStr
750757
const uint32_t m_maxInstanceCount;
751758

752759
private:
753-
struct DynamicUpCastingSpanIterator
754-
{
755-
inline bool operator!=(const DynamicUpCastingSpanIterator& other) const {return ptr!=other.ptr;}
756-
757-
inline DynamicUpCastingSpanIterator operator++() {return {ptr++};}
758-
759-
inline const IGPUBottomLevelAccelerationStructure* operator*() const {return dynamic_cast<const IGPUBottomLevelAccelerationStructure*>(ptr->get());}
760-
761-
std::span<const core::smart_refctd_ptr<const core::IReferenceCounted>>::iterator ptr;
762-
};
763760
friend class ILogicalDevice;
764761
friend class IQueue;
762+
765763
inline const core::unordered_set<blas_smart_ptr_t>* getPendingBuildTrackedBLASes(const build_ver_t buildVer) const
766764
{
767765
const auto found = std::find_if(m_pendingBuilds.begin(),m_pendingBuilds.end(),[buildVer](const auto& item)->bool{return item.ordinal==buildVer;});

include/nbl/video/IGPUCommandBuffer.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,12 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
552552
{
553553
auto oit = reserveReferences(std::distance(begin,end));
554554
if (oit)
555-
while (begin!=end)
556-
*(oit++) = core::smart_refctd_ptr<const core::IReferenceCounted>(*(begin++));
557-
return oit;
555+
{
556+
while (begin!=end)
557+
*(oit++) = core::smart_refctd_ptr<const core::IReferenceCounted>(*(begin++));
558+
return true;
559+
}
560+
return false;
558561
}
559562
inline bool recordReferences(const std::span<const IReferenceCounted*> refs) {return recordReferences(refs.begin(),refs.end());}
560563

@@ -569,8 +572,9 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
569572
m_TLASTrackingOps.emplace_back(TLASTrackingWrite{.src={oit,size},.dst=tlas});
570573
while (beginBLASes!=endBLASes)
571574
*(oit++) = core::smart_refctd_ptr<const core::IReferenceCounted>(*(beginBLASes++));
575+
return true;
572576
}
573-
return oit;
577+
return false;
574578
}
575579

576580
virtual bool insertDebugMarker(const char* name, const core::vector4df_SIMD& color = core::vector4df_SIMD(1.0, 1.0, 1.0, 1.0)) = 0;
@@ -885,7 +889,7 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
885889
template<typename IndirectCommand> requires nbl::is_any_of_v<IndirectCommand, hlsl::DrawArraysIndirectCommand_t, hlsl::DrawElementsIndirectCommand_t>
886890
bool invalidDrawIndirectCount(const asset::SBufferBinding<const IGPUBuffer>& indirectBinding, const asset::SBufferBinding<const IGPUBuffer>& countBinding, const uint32_t maxDrawCount, const uint32_t stride);
887891

888-
core::smart_refctd_ptr<const core::IReferenceCounted>* reserveReferences(const uint32_t size);
892+
IGPUCommandPool::CTrackedIterator reserveReferences(const uint32_t size);
889893

890894
// This bound descriptor set record doesn't include the descriptor sets whose layout has _any_ one of its bindings
891895
// created with IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT
@@ -896,7 +900,9 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
896900
// The Command Pool already tracks resources referenced in the Build Infos or Copies From Memory (Deserializations), so we only need pointers into those records.
897901
struct TLASTrackingWrite
898902
{
899-
std::span<const core::smart_refctd_ptr<const IReferenceCounted>> src;
903+
// TODO: pack a little more efficiently so we can recover `CTrackedIterator` more easily
904+
IGPUCommandPool::CTrackedIterator srcBegin;
905+
uint32_t count;
900906
IGPUTopLevelAccelerationStructure* dst;
901907
};
902908
struct TLASTrackingCopy

0 commit comments

Comments
 (0)