Skip to content

Commit b044144

Browse files
author
devsh
committed
the deferred TLAS descriptor writes need to refcount the TLASes
1 parent e0fe7ed commit b044144

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

include/nbl/video/utilities/CAssetConverter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,13 +1136,13 @@ class CAssetConverter : public core::IReferenceCounted
11361136
{
11371137
inline bool operator==(const SDeferredTLASWrite& other) const
11381138
{
1139-
return dstSet == other.dstSet && binding == other.binding && arrayElement == other.arrayElement;
1139+
return dstSet==other.dstSet && binding==other.binding && arrayElement==other.arrayElement;
11401140
}
11411141

11421142
IGPUDescriptorSet* dstSet;
11431143
uint32_t binding;
11441144
uint32_t arrayElement;
1145-
const IGPUTopLevelAccelerationStructure* tlas;
1145+
core::smart_refctd_ptr<const IGPUTopLevelAccelerationStructure> tlas;
11461146
};
11471147
struct SDeferredTLASWriteHasher
11481148
{

src/nbl/video/utilities/CAssetConverter.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ class GetDependantVisit<ICPUDescriptorSet> : public GetDependantVisitBase<ICPUDe
19601960
// the RLE will always finish a write because a single binding can only be a single descriptor type, important that the TLAS path happens after that check
19611961
if constexpr (std::is_same_v<DepType,ICPUTopLevelAccelerationStructure>)
19621962
{
1963-
deferredTLASWrites.push_back({nullptr,binding.data,element,depObj.get()});
1963+
deferredTLASWrites.push_back({nullptr,binding.data,element,depObj});
19641964
return true;
19651965
}
19661966
//
@@ -3586,11 +3586,9 @@ auto CAssetConverter::reserve(const SInputs& inputs) -> SReserveResult
35863586
auto& stagingCache = std::get<SReserveResult::staging_cache_t<AssetType>>(retval.m_stagingCaches);
35873587
phmap::erase_if(stagingCache,[](const auto& entry)->bool
35883588
{
3589-
if constexpr (std::is_same_v<AssetType,ICPUTopLevelAccelerationStructure>)
3590-
{
3591-
// TODO: gather into m_deferredTLASDescriptorWrites
3592-
}
3593-
return entry.first->getReferenceCount()==1;
3589+
if (entry.first->getReferenceCount()==1)
3590+
return true;
3591+
return false;
35943592
}
35953593
);
35963594
};
@@ -3608,19 +3606,20 @@ auto CAssetConverter::reserve(const SInputs& inputs) -> SReserveResult
36083606
pruneStaging.template operator()<ICPUImageView>();
36093607
pruneStaging.template operator()<ICPUBufferView>();
36103608
pruneStaging.template operator()<ICPUImage>();
3611-
// need to nerf any writes to descriptor sets which don't exist anymore before checking the refcounts on them
3609+
// because Descriptor Sets don't hold onto TLASes yet, we need to drop the TLASes in deferred descriptor writes
36123610
phmap::erase_if(retval.m_deferredTLASDescriptorWrites,[&](const auto& entry)->bool
36133611
{
36143612
auto& dsStaging = std::get<SReserveResult::staging_cache_t<ICPUDescriptorSet>>(retval.m_stagingCaches);
3615-
return dsStaging.find(entry.dstSet)!=dsStaging.end();
3613+
return dsStaging.find(entry.dstSet)==dsStaging.end();
36163614
}
36173615
);
36183616
pruneStaging.template operator()<ICPUTopLevelAccelerationStructure>();
3617+
// go over
36193618
pruneStaging.template operator()<ICPUBottomLevelAccelerationStructure>();
36203619
pruneStaging.template operator()<ICPUBuffer>();
36213620
}
36223621

3623-
// TODO: defer the conversion requests until final objects are known (or knock them out) -> maybe change the conversion requests to unordered_map ?
3622+
// TODO: prune the conversion requests -> maybe change the conversion requests to unordered_map ?
36243623

36253624
// TODO: only now get the queue flags
36263625

@@ -5249,7 +5248,7 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
52495248
for (auto& inWrite : tlasWriteMap)
52505249
{
52515250
// I know what I'm doing, this member has no influence on the set key hash
5252-
auto tlas = core::smart_refctd_ptr<IGPUTopLevelAccelerationStructure>(const_cast<IGPUTopLevelAccelerationStructure*>(inWrite.tlas));
5251+
auto tlas = core::smart_refctd_ptr<IGPUTopLevelAccelerationStructure>(const_cast<IGPUTopLevelAccelerationStructure*>(inWrite.tlas.get()));
52535252
assert(tlas);
52545253
if (missingDependent.template operator()<ICPUTopLevelAccelerationStructure>(tlas.get()))
52555254
continue;

0 commit comments

Comments
 (0)