Skip to content

Commit 5fc0da6

Browse files
author
devsh
committed
make the Host Acceleration Structure builds set
1 parent b84fae1 commit 5fc0da6

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

include/nbl/video/IDeferredOperation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ class IDeferredOperation : public IBackendObject
3030
{
3131
const auto retval = execute_impl();
3232
if (retval==STATUS::COMPLETED || retval==STATUS::_ERROR)
33+
{
34+
std::lock_guard lock(m_completionMutex);
35+
if (m_callback)
36+
{
37+
m_callback(this);
38+
m_callback = {};
39+
}
3340
m_resourceTracking.clear();
41+
}
3442
return retval;
3543
}
3644

@@ -66,6 +74,8 @@ class IDeferredOperation : public IBackendObject
6674
private:
6775
friend class ILogicalDevice;
6876
// when we improve allocators, etc. we'll stop using STL containers here
77+
std::mutex m_completionMutex;
78+
std::function<void(IDeferredOperation*)> m_callback;
6979
core::vector<core::smart_refctd_ptr<const IReferenceCounted>> m_resourceTracking;
7080
};
7181

include/nbl/video/IGPUCommandBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ class NBL_API2 IGPUCommandBuffer : public IBackendObject
872872
// If the user wants the builds to be tracking, and make the TLAS remember the BLASes that have been built into it.
873873
// NOTE: We know that a TLAS may be rebuilt multiple times per frame on purpose and not only the final BLASes need to be kept alive till submission finishes.
874874
// However, the Command Pool already tracks resources referenced in the Build Infos, so we only need pointers into those records.
875-
core::unordered_map<const IGPUTopLevelAccelerationStructure*,const IGPUTopLevelAccelerationStructure::blas_smart_ptr_t*> m_TLASToBLASReferenceSets;
875+
core::unordered_map<IGPUTopLevelAccelerationStructure*,std::span<const IGPUTopLevelAccelerationStructure::blas_smart_ptr_t>> m_TLASToBLASReferenceSets;
876876

877877
const IGPUGraphicsPipeline* m_boundGraphicsPipeline;
878878
const IGPUComputePipeline* m_boundComputePipeline;

include/nbl/video/ILogicalDevice.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,41 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
539539
// track things created
540540
if (result==DEFERRABLE_RESULT::DEFERRED)
541541
{
542+
constexpr bool IsTLAS = std::is_same_v<AccelerationStructure,IGPUTopLevelAccelerationStructure>;
543+
struct TLASCallback
544+
{
545+
// upon completion set the BLASes tracked
546+
inline void operator()(IDeferredOperation*) const
547+
{
548+
for (const auto& set : m_TLASToBLASReferenceSets)
549+
{
550+
auto tlas = set.first;
551+
// we know the build is completed immediately after performing it, so we get our pending stamp then
552+
tlas->setTrackedBLASes(set.second.begin(),set.second.end(),tlas->registerNextBuildVer());
553+
}
554+
}
555+
556+
// the rawpointers are already smartpointers in whatever else the `fillTracking` declared above writes
557+
core::unordered_map<IGPUTopLevelAccelerationStructure*,std::span<const IGPUTopLevelAccelerationStructure::blas_smart_ptr_t>> m_TLASToBLASReferenceSets;
558+
} callback = {};
559+
542560
auto& tracking = deferredOperation->m_resourceTracking;
543561
tracking.resize(trackingReservation);
544562
auto oit = tracking.data();
545563
for (const auto& info : infos)
564+
{
546565
oit = info.fillTracking(oit);
566+
if constexpr (IsTLAS)
567+
{
568+
const auto blasCount = info.trackedBLASes.size();
569+
if (blasCount)
570+
callback.m_TLASToBLASReferenceSets[info.dstAS] = {reinterpret_cast<const IGPUTopLevelAccelerationStructure::blas_smart_ptr_t*>(oit-blasCount),blasCount};
571+
else
572+
callback.m_TLASToBLASReferenceSets[info.dstAS] = {};
573+
}
574+
}
575+
if constexpr (IsTLAS)
576+
deferredOperation->m_callback = std::move(callback);
547577
}
548578
return result!=DEFERRABLE_RESULT::SOME_ERROR;
549579
}

src/nbl/video/IGPUCommandBuffer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,13 @@ uint32_t IGPUCommandBuffer::buildAccelerationStructures_common(const std::span<c
840840
oit = info.fillTracking(oit);
841841
// we still need to clear the BLAS tracking list if the TLAS has nothing to track
842842
if constexpr (std::is_same_v<DeviceBuildInfo,IGPUTopLevelAccelerationStructure::DeviceBuildInfo>)
843-
m_TLASToBLASReferenceSets[info.dstAS] = info.trackedBLASes.empty() ? nullptr:reinterpret_cast<const IGPUTopLevelAccelerationStructure::blas_smart_ptr_t*>(oit-info.trackedBLASes.size());
843+
{
844+
const auto blasCount = info.trackedBLASes.size();
845+
if (blasCount)
846+
m_TLASToBLASReferenceSets[info.dstAS] = {reinterpret_cast<const IGPUTopLevelAccelerationStructure::blas_smart_ptr_t*>(oit-blasCount),blasCount};
847+
else
848+
m_TLASToBLASReferenceSets[info.dstAS] = {};
849+
}
844850
}
845851

846852
return totalGeometries;

0 commit comments

Comments
 (0)