@@ -4232,32 +4232,87 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
4232
4232
};
4233
4233
if (blasCount==0 || pipelineBarrier (computeCmdBuf,{.memBarriers ={&readBLASInTLASBuildBarrier,1 }}," Failed to sync BLAS with TLAS build!" ))
4234
4234
{
4235
- core::vector<IGPUTopLevelAccelerationStructure *> compactions;
4235
+ core::vector<const IGPUAccelerationStructure *> compactions;
4236
4236
compactions.reserve (tlasCount);
4237
4237
// build
4238
4238
for (const auto & tlasToBuild : tlasesToBuild)
4239
4239
{
4240
- // allocate scratch
4241
- // check dependents
4242
- // stream build infos
4243
- // record builds
4244
- // record compaction queries
4240
+ // allocate scratch
4241
+ // check dependents
4242
+ // stream build infos
4243
+ // record builds
4245
4244
}
4246
4245
computeCmdBuf->cmdbuf ->endDebugMarker ();
4247
4246
// no longer need this info
4248
4247
compactedBLASMap.clear ();
4249
4248
// compact
4250
4249
computeCmdBuf->cmdbuf ->beginDebugMarker (" Asset Converter Compact TLASes" );
4251
- // compact needs to wait for Build
4252
- if (!compactions.empty () && pipelineBarrier (computeCmdBuf,{.memBarriers ={&readASInASCompactBarrier,1 }}," Failed to sync Acceleration Structure builds with compactions!" ))
4250
+ // compact needs to wait for Build then record queries
4251
+ if (!compactions.empty () &&
4252
+ pipelineBarrier (computeCmdBuf,{.memBarriers ={&readASInASCompactBarrier,1 }}," Failed to sync Acceleration Structure builds with compactions!" ) &&
4253
+ computeCmdBuf->cmdbuf ->writeAccelerationStructureProperties (compactions,IQueryPool::TYPE::ACCELERATION_STRUCTURE_COMPACTED_SIZE,queryPool.get (),0 )
4254
+ )
4253
4255
{
4254
- // drain compute
4256
+ // drain compute
4255
4257
// get queries
4256
- for (auto * tlas : compactions)
4258
+ core::vector<size_t > sizes (compactions.size ());
4259
+ if (device->getQueryPoolResults (
4260
+ queryPool.get (),0 ,compactions.size (),sizes.data (),sizeof (size_t ),
4261
+ bitflag (IQueryPool::RESULTS_FLAGS::WAIT_BIT)|IQueryPool::RESULTS_FLAGS::_64_BIT
4262
+ ))
4257
4263
{
4258
- // recreate Acceleration Structure
4259
- // record compaction
4260
- // insert into compaction map
4264
+ auto logFail = [](const char * msg)->void
4265
+ {
4266
+ // TODO
4267
+ };
4268
+ auto itSize = sizes.data ();
4269
+ // create buffers
4270
+ // recreate and compact Acceleration Structures
4271
+ for (auto * pas : compactions)
4272
+ {
4273
+ const size_t compactedSize = *(itSize++);
4274
+ const auto * as = static_cast <const IGPUTopLevelAccelerationStructure*>(pas);
4275
+ // recreate Acceleration Structure
4276
+ smart_refctd_ptr<IGPUBuffer> buff;
4277
+ {
4278
+ const auto * oldBuffer = as->getCreationParams ().bufferRange .buffer .get ();
4279
+ //
4280
+ IGPUBuffer::SCreationParams creationParams = { {.size =compactedSize,.usage =IGPUBuffer::E_USAGE_FLAGS::EUF_ACCELERATION_STRUCTURE_STORAGE_BIT},{} };
4281
+ creationParams.queueFamilyIndexCount = oldBuffer->getCachedCreationParams ().queueFamilyIndexCount ;
4282
+ // TODO creationParams.queueFamilyIndices = oldBuffer->;
4283
+ buff = device->createBuffer (std::move (creationParams));
4284
+ if (!buff)
4285
+ {
4286
+ logFail (" create Buffer backing the Compacted Acceleration Structure" );
4287
+ continue ;
4288
+ }
4289
+ // allocate new memory
4290
+ auto bufReqs = buff->getMemoryReqs ();
4291
+ bufReqs.memoryTypeBits &= device->getPhysicalDevice ()->getDeviceLocalMemoryTypeBits ();
4292
+ if (!params.compactedASAllocator ->allocate (bufReqs,nullptr ,IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT).isValid ())
4293
+ {
4294
+ logFail (" allocate and bind memory to the Buffer backing the Compacted Acceleration Structure" );
4295
+ continue ;
4296
+ }
4297
+ }
4298
+ IGPUTopLevelAccelerationStructure::SCreationParams creationParams = {pas->getCreationParams ()};
4299
+ creationParams.bufferRange = {.offset =0 ,.size =compactedSize,.buffer =buff};
4300
+ creationParams.maxInstanceCount = as->getMaxInstanceCount ();
4301
+ auto compactedAS = device->createTopLevelAccelerationStructure (std::move (creationParams));
4302
+ if (!compactedAS)
4303
+ {
4304
+ logFail (" create the Compacted Acceleration Structure" );
4305
+ continue ;
4306
+ }
4307
+ // record compaction
4308
+ if (!computeCmdBuf->cmdbuf ->copyAccelerationStructure ({.src =as,.dst =compactedAS.get (),.mode =IGPUAccelerationStructure::COPY_MODE::COMPACT}))
4309
+ {
4310
+ logFail (" record Acceleration Structure compaction" );
4311
+ continue ;
4312
+ }
4313
+ // insert into compaction map
4314
+ compactedTLASMap[as] = std::move (compactedAS);
4315
+ }
4261
4316
}
4262
4317
}
4263
4318
}
0 commit comments