Skip to content

Commit 31163b3

Browse files
author
devsh
committed
make sure compacted AS has the same Debug Name, write the build-flush function
1 parent 1e20efc commit 31163b3

File tree

1 file changed

+66
-15
lines changed

1 file changed

+66
-15
lines changed

src/nbl/video/utilities/CAssetConverter.cpp

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,16 +4235,61 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
42354235
core::vector<const IGPUAccelerationStructure*> compactions;
42364236
compactions.reserve(tlasCount);
42374237
// build
4238-
for (const auto& tlasToBuild : tlasesToBuild)
42394238
{
4240-
// allocate scratch
4241-
// check dependents
4242-
// stream build infos
4243-
// record builds
4239+
//
4240+
core::vector<IGPUTopLevelAccelerationStructure::DeviceBuildInfo> buildInfos;
4241+
buildInfos.reserve(tlasCount);
4242+
core::vector<const IGPUBottomLevelAccelerationStructure*> trackedBLASes;
4243+
trackedBLASes.reserve(hlsl::max(tlasCount,blasCount));
4244+
core::vector<IGPUTopLevelAccelerationStructure::BuildRangeInfo> rangeInfos;
4245+
rangeInfos.reserve(tlasCount);
4246+
auto recordBuilds = [&]()->void
4247+
{
4248+
// rewrite the trackedBLASes pointers
4249+
for (auto& info : buildInfos)
4250+
{
4251+
const auto offset = info.trackedBLASes.data();
4252+
info.trackedBLASes = {trackedBLASes.data()+reinterpret_cast<const size_t&>(offset),info.trackedBLASes.size()};
4253+
}
4254+
//
4255+
if (!buildInfos.empty() && !computeCmdBuf->cmdbuf->buildAccelerationStructures({buildInfos},rangeInfos.data()))
4256+
for (const auto& info : buildInfos)
4257+
{
4258+
const auto pFoundHash = findInStaging.operator()<ICPUTopLevelAccelerationStructure>(info.dstAS);
4259+
markFailureInStaging(info.dstAS,pFoundHash); // TODO: make messages configurable message
4260+
}
4261+
buildInfos.clear();
4262+
rangeInfos.clear();
4263+
trackedBLASes.clear();
4264+
};
4265+
//
4266+
for (const auto& tlasToBuild : tlasesToBuild)
4267+
{
4268+
const auto as = tlasToBuild.gpuObj;
4269+
const auto pFoundHash = findInStaging.operator()<ICPUTopLevelAccelerationStructure>(as);
4270+
const auto instances = tlasToBuild.canonical->getInstances();
4271+
// allocate scratch and build inputs
4272+
// if fail then flush
4273+
// stream the info in && check dependents
4274+
// prepare build infos
4275+
auto& buildInfo = buildInfos.emplace_back();
4276+
buildInfo.scratch = {};
4277+
// buildInfo.buildFlags = tlasToBuild.getBuildFlags();
4278+
buildInfo.dstAS = as;
4279+
buildInfo.instanceData = {};
4280+
// be based cause vectors can grow
4281+
{
4282+
const auto offset = trackedBLASes.size();
4283+
using p_p_BLAS_t = const IGPUBottomLevelAccelerationStructure**;
4284+
buildInfo.trackedBLASes = {reinterpret_cast<const p_p_BLAS_t&>(offset),instances.size()};
4285+
}
4286+
rangeInfos.emplace_back(instances.size(),0u);
4287+
}
4288+
recordBuilds();
4289+
computeCmdBuf->cmdbuf->endDebugMarker();
4290+
// no longer need this info
4291+
compactedBLASMap.clear();
42444292
}
4245-
computeCmdBuf->cmdbuf->endDebugMarker();
4246-
// no longer need this info
4247-
compactedBLASMap.clear();
42484293
// compact
42494294
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Compact TLASes");
42504295
// compact needs to wait for Build then record queries
@@ -4261,12 +4306,12 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
42614306
bitflag(IQueryPool::RESULTS_FLAGS::WAIT_BIT)|IQueryPool::RESULTS_FLAGS::_64_BIT
42624307
))
42634308
{
4264-
auto logFail = [](const char* msg)->void
4309+
auto logFail = [logger](const char* msg, const IGPUAccelerationStructure* as)->void
42654310
{
4266-
//TODO
4311+
logger.log("Failed to %s for \"%s\"", system::ILogger::ELL_ERROR,as->getObjectDebugName());
42674312
};
42684313
auto itSize = sizes.data();
4269-
// create buffers
4314+
// create buffers
42704315
// recreate and compact Acceleration Structures
42714316
for (auto* pas : compactions)
42724317
{
@@ -4283,15 +4328,15 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
42834328
buff = device->createBuffer(std::move(creationParams));
42844329
if (!buff)
42854330
{
4286-
logFail("create Buffer backing the Compacted Acceleration Structure");
4331+
logFail("create Buffer backing the Compacted Acceleration Structure",pas);
42874332
continue;
42884333
}
42894334
// allocate new memory
42904335
auto bufReqs = buff->getMemoryReqs();
42914336
bufReqs.memoryTypeBits &= device->getPhysicalDevice()->getDeviceLocalMemoryTypeBits();
42924337
if (!params.compactedASAllocator->allocate(bufReqs,nullptr,IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT).isValid())
42934338
{
4294-
logFail("allocate and bind memory to the Buffer backing the Compacted Acceleration Structure");
4339+
logFail("allocate and bind memory to the Buffer backing the Compacted Acceleration Structure",pas);
42954340
continue;
42964341
}
42974342
}
@@ -4301,13 +4346,19 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
43014346
auto compactedAS = device->createTopLevelAccelerationStructure(std::move(creationParams));
43024347
if (!compactedAS)
43034348
{
4304-
logFail("create the Compacted Acceleration Structure");
4349+
logFail("create the Compacted Acceleration Structure",pas);
43054350
continue;
43064351
}
4352+
// set the debug name
4353+
{
4354+
std::string debugName = as->getObjectDebugName();
4355+
debugName += " compacted";
4356+
compactedAS->setObjectDebugName(debugName.c_str());
4357+
}
43074358
// record compaction
43084359
if (!computeCmdBuf->cmdbuf->copyAccelerationStructure({.src=as,.dst=compactedAS.get(),.mode=IGPUAccelerationStructure::COPY_MODE::COMPACT}))
43094360
{
4310-
logFail("record Acceleration Structure compaction");
4361+
logFail("record Acceleration Structure compaction",compactedAS.get());
43114362
continue;
43124363
}
43134364
// insert into compaction map

0 commit comments

Comments
 (0)