Skip to content

Commit 6b29da5

Browse files
author
devsh
committed
ownership transfers of TLASes
1 parent 26ba094 commit 6b29da5

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/nbl/video/utilities/CAssetConverter.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,9 +3692,13 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
36923692
auto pFoundHash = findInStaging.operator()<ICPUBuffer>(buffer);
36933693
//
36943694
const auto ownerQueueFamily = checkOwnership(buffer,params.getFinalOwnerQueueFamily(buffer,*pFoundHash),transferFamily);
3695-
bool success = ownerQueueFamily!=QueueFamilyInvalid;
3695+
if (ownerQueueFamily==QueueFamilyInvalid)
3696+
{
3697+
markFailureInStaging("invalid Final Queue Family given by user callback",item.canonical,buffer,pFoundHash);
3698+
continue;
3699+
}
36963700
// do the upload
3697-
success = success && params.utilities->updateBufferRangeViaStagingBuffer(*params.transfer,range,item.canonical->getPointer());
3701+
const bool success = params.utilities->updateBufferRangeViaStagingBuffer(*params.transfer,range,item.canonical->getPointer());
36983702
// current recording buffer may have changed
36993703
xferCmdBuf = params.transfer->getCommandBufferForRecording();
37003704
if (!success)
@@ -4274,6 +4278,9 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
42744278
if (blasCount)
42754279
{
42764280
// build
4281+
{
4282+
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Build BLASes START");
4283+
computeCmdBuf->cmdbuf->endDebugMarker();
42774284
#ifdef NBL_ACCELERATION_STRUCTURE_CONVERSION
42784285
constexpr auto GeometryIsAABBFlag = ICPUBottomLevelAccelerationStructure::BUILD_FLAGS::GEOMETRY_TYPE_IS_AABB_BIT;
42794286

@@ -4326,12 +4333,19 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
43264333
}
43274334
}
43284335
#endif
4336+
blasesToBuild.clear();
4337+
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Build BLASes END");
4338+
computeCmdBuf->cmdbuf->endDebugMarker();
4339+
}
43294340
// compact
4341+
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Compact BLASes START");
4342+
computeCmdBuf->cmdbuf->endDebugMarker();
43304343
{
43314344
// the already compacted BLASes need to be written into the TLASes using them, want to swap them out ASAP
43324345
//reservations.m_blasBuildMap[canonical].gpuBLAS = compacted;
43334346
}
4334-
blasesToBuild.clear();
4347+
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Compact BLASes END");
4348+
computeCmdBuf->cmdbuf->endDebugMarker();
43354349
}
43364350

43374351
// Device TLAS builds
@@ -4351,7 +4365,10 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
43514365
if (blasCount==0 || pipelineBarrier(computeCmdBuf,{.memBarriers={&readBLASInTLASBuildBarrier,1}},"Failed to sync BLAS with TLAS build!"))
43524366
{
43534367
core::vector<const IGPUAccelerationStructure*> compactions;
4368+
// 0xffFFffFFu when not releasing ownership, otherwise index into `ownershipTransfers` where the ownership release for the old buffer was
4369+
core::vector<uint32_t> compactedOwnershipReleaseIndices;
43544370
compactions.reserve(tlasCount);
4371+
compactedOwnershipReleaseIndices.reserve(tlasCount);
43554372
// build
43564373
{
43574374
//
@@ -4395,6 +4412,13 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
43954412
dedupBLASesUsed.clear();
43964413
const auto as = tlasToBuild.gpuObj;
43974414
const auto pFoundHash = findInStaging.operator()<ICPUTopLevelAccelerationStructure>(as);
4415+
const auto& backingRange = as->getCreationParams().bufferRange;
4416+
const auto ownerQueueFamily = checkOwnership(backingRange.buffer.get(),params.getFinalOwnerQueueFamily(backingRange.buffer.get(),*pFoundHash),computeFamily);
4417+
if (ownerQueueFamily==QueueFamilyInvalid)
4418+
{
4419+
markFailureInStaging("invalid Final Queue Family given by user callback",tlasToBuild.canonical,as,pFoundHash);
4420+
continue;
4421+
}
43984422
const auto instances = tlasToBuild.canonical->getInstances();
43994423
const auto instanceCount = static_cast<uint32_t>(instances.size());
44004424
size_t instanceDataSize = 0;
@@ -4545,12 +4569,31 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
45454569
}
45464570
// no special extra byte offset into the instance buffer
45474571
rangeInfos.emplace_back(instanceCount,0u);
4572+
//
4573+
const bool willCompact = tlasToBuild.compact();
4574+
if (willCompact)
4575+
compactions.push_back(as);
4576+
// enqueue ownership release if necessary
4577+
if (ownerQueueFamily!=IQueue::FamilyIgnored)
4578+
ownershipTransfers.push_back({
4579+
.barrier = {
4580+
.dep = {
4581+
.srcStageMask = PIPELINE_STAGE_FLAGS::ACCELERATION_STRUCTURE_BUILD_BIT,
4582+
.srcAccessMask = ACCESS_FLAGS::ACCELERATION_STRUCTURE_WRITE_BIT
4583+
// leave rest empty, we can release whenever after the copies and before the semaphore signal
4584+
},
4585+
.ownershipOp = ownership_op_t::RELEASE,
4586+
.otherQueueFamilyIndex = ownerQueueFamily
4587+
},
4588+
.range = backingRange
4589+
});
45484590
}
45494591
// finish the last batch
45504592
recordBuildCommands();
45514593
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Compact TLASes END");
45524594
computeCmdBuf->cmdbuf->endDebugMarker();
45534595
}
4596+
tlasesToBuild.clear();
45544597
// compact
45554598
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Compact TLASes START");
45564599
computeCmdBuf->cmdbuf->endDebugMarker();
@@ -4639,6 +4682,9 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
46394682
logFail("record Acceleration Structure compaction",compactedAS.get());
46404683
continue;
46414684
}
4685+
// modify the ownership release
4686+
if (const auto ix=compactedOwnershipReleaseIndices[i]; ix<ownershipTransfers.size())
4687+
ownershipTransfers[ix].range = compactedAS->getCreationParams().bufferRange;
46424688
// insert into compaction map
46434689
compactedTLASMap[as] = std::move(compactedAS);
46444690
}
@@ -4647,7 +4693,6 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
46474693
}
46484694
computeCmdBuf->cmdbuf->beginDebugMarker("Asset Converter Compact TLASes END");
46494695
computeCmdBuf->cmdbuf->endDebugMarker();
4650-
tlasesToBuild.clear();
46514696
}
46524697

46534698
// release ownership

0 commit comments

Comments
 (0)