Skip to content

Commit 1403f33

Browse files
author
devsh
committed
improve CAssetConverter to take into account that not every asset_traits<AssetType>::video_t inherits from IBackendObject
1 parent 569839e commit 1403f33

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/nbl/video/utilities/CAssetConverter.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,9 @@ class GetDependantVisit<ICPUPolygonGeometry> : public GetDependantVisitBase<ICPU
21182118
}
21192119

21202120
IGPUPolygonGeometry::SCreationParams creationParams = {};
2121+
// has to be public because of aggregate init, but its only for internal usage!
2122+
core::vector<IGPUPolygonGeometry::SJointWeight> jointWeightViews = {};
2123+
core::vector<IGPUPolygonGeometry::SDataView> auxAttributeViews = {};
21212124

21222125
protected:
21232126
bool descend_impl(
@@ -2180,9 +2183,6 @@ class GetDependantVisit<ICPUPolygonGeometry> : public GetDependantVisitBase<ICPU
21802183
creationParams.indexing = nullptr;
21812184
return retval;
21822185
}
2183-
2184-
core::vector<IGPUPolygonGeometry::SJointWeight> jointWeightViews;
2185-
core::vector<IGPUPolygonGeometry::SDataView> auxAttributeViews;
21862186
};
21872187

21882188

@@ -2656,7 +2656,8 @@ struct conversions_t
26562656
return;
26572657
}
26582658
// set debug names on everything!
2659-
setDebugName(conv,output->get(),contentHash,uniqueCopyGroupID);
2659+
if constexpr (std::is_base_of_v<IBackendObject,typename asset_traits<AssetType>::video_t>)
2660+
setDebugName(conv,output->get(),contentHash,uniqueCopyGroupID);
26602661
}
26612662

26622663
// Since the dfsCache has the original asset pointers as keys, we map in reverse (multiple `instance_t` can map to the same unique content hash and GPU object)
@@ -3885,6 +3886,11 @@ auto CAssetConverter::reserve(const SInputs& inputs) -> SReserveResult
38853886
return retval;
38863887
}
38873888

3889+
3890+
// Maps GPU Object back to the output array index
3891+
template<asset::Asset AssetType>
3892+
using reverse_map_t = core::unordered_map<const typename asset_traits<AssetType>::video_t*,uint32_t>;
3893+
38883894
//
38893895
ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResult& reservations, SConvertParams& params)
38903896
{
@@ -3926,16 +3932,20 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
39263932
};
39273933

39283934
// wipe gpu item in staging cache (this may drop it as well if it was made for only a root asset == no users)
3929-
core::unordered_map<const IBackendObject*, uint32_t> outputReverseMap;
3930-
core::for_each_in_tuple(reservations.m_gpuObjects,[&outputReverseMap](const auto& gpuObjects)->void
3935+
core::tuple_transform_t<reverse_map_t,supported_asset_types> outputReverseMaps;
3936+
core::for_each_in_tuple(reservations.m_gpuObjects,[&outputReverseMaps](const auto& gpuObjects)->void
39313937
{
39323938
uint32_t i = 0;
39333939
for (const auto& gpuObj : gpuObjects)
3934-
outputReverseMap[gpuObj.value.get()] = i++;
3940+
{
3941+
const auto* ptr = gpuObj.value.get();
3942+
std::get<core::unordered_map<decltype(ptr),uint32_t>>(outputReverseMaps)[ptr] = i++;
3943+
}
39353944
}
39363945
);
3937-
auto markFailure = [&reservations,&outputReverseMap,logger]<Asset AssetType>(const char* message, smart_refctd_ptr<const AssetType>* canonical, typename SReserveResult::staging_cache_t<AssetType>::mapped_type* cacheNode)->void
3946+
auto markFailure = [&reservations,&outputReverseMaps,logger]<Asset AssetType>(const char* message, smart_refctd_ptr<const AssetType>* canonical, typename SReserveResult::staging_cache_t<AssetType>::mapped_type* cacheNode)->void
39383947
{
3948+
auto& outputReverseMap = std::get<reverse_map_t<AssetType>>(outputReverseMaps);
39393949
// wipe the smart pointer to the canonical, make sure we release that memory ASAP if no other user is around
39403950
*canonical = nullptr;
39413951
// also drop the smart pointer from the output array so failures release memory quickly
@@ -5499,6 +5509,7 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
54995509
if (const auto ix=compactedOwnershipReleaseIndices[i]; ix<ownershipTransfers.size())
55005510
ownershipTransfers[ix].range = compactedAS->getCreationParams().bufferRange;
55015511
// swap out the conversion result
5512+
auto& outputReverseMap = std::get<reverse_map_t<CPUAccelerationStructure>>(outputReverseMaps);
55025513
const auto foundIx = outputReverseMap.find(srcAS);
55035514
if (foundIx!=outputReverseMap.end())
55045515
{
@@ -5659,7 +5670,7 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
56595670
return;
56605671
depsMissing = missingDependent.template operator()<ICPUBuffer>(view.src.buffer.get());
56615672
};
5662-
if (const auto* view=pGPUObj->getJointOBBView(); view)
5673+
if (const auto* view=pGpuObj->getJointOBBView(); view)
56635674
checkView(*view);
56645675
checkView(pGpuObj->getIndexView());
56655676
checkView(pGpuObj->getNormalView());

0 commit comments

Comments
 (0)