SpiecsEngine
 
Loading...
Searching...
No Matches

◆ CmdCreateBLAS()

void Spices::VulkanRayTracing::CmdCreateBLAS ( VkCommandBuffer cmdBuf,
const std::vector< uint32_t > & indices,
std::vector< BuildAccelerationStructure > & buildAs,
VkDeviceAddress scratchAddress,
std::shared_ptr< VulkanQueryPool > queryPool ) const
private

Creating the bottom level acceleration structure for all indices of buildAs vector. The array of BuildAccelerationStructure was created in buildBlas and the vector of indices limits the number of BLAS to create at once. This limits the amount of memory needed when compacting the BLAS.

Parameters
[in]cmdBufVkCommandBuffer.
[in]indicesBLAS indices.
[in]buildAsBuildAccelerationStructure.
[in]scratchAddress.
[in]queryPoolQuery AccelerationStructure data.

Querying the compaction size.

creating all the BLAS defined by the index chunk.

Actual allocation of buffer and acceleration structure.

BuildInfo #2 part.

Building the bottom - level - acceleration - structure.

Since the scratch buffer is reused across builds, we need a barrier to ensure one build is finished before starting the next one.

Add the size query only if needed.

Add a query to find the 'real' amount of memory needed, use for compaction.

Querying the compaction size.

creating all the BLAS defined by the index chunk.

Actual allocation of buffer and acceleration structure.

BuildInfo #2 part.

Building the bottom - level - acceleration - structure.

Since the scratch buffer is reused across builds, we need a barrier to ensure one build is finished before starting the next one.

Add the size query only if needed.

Add a query to find the 'real' amount of memory needed, use for compaction.

Definition at line 469 of file VulkanRayTracing.cpp.

476 {
478
482 if (queryPool)
483 {
484 queryPool->Reset(cmdBuf);
485 }
486
487 uint32_t queryCnt{ 0 };
488
492 for (const auto& idx : indices)
493 {
497 VkAccelerationStructureCreateInfoKHR createInfo{};
498 createInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR;
499 createInfo.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
500 createInfo.size = buildAs[idx].sizeInfo.accelerationStructureSize; // Will be used to allocate memory.
501
502 *buildAs[idx].as = CreateAcceleration(createInfo);
503
507 buildAs[idx].buildInfo.dstAccelerationStructure = buildAs[idx].as->accel->Get(); // Setting where the build lands
508 buildAs[idx].buildInfo.scratchData.deviceAddress = scratchAddress; // All build are using the same scratch buffer
509
513 m_VulkanState.m_VkFunc.vkCmdBuildAccelerationStructuresKHR(cmdBuf, 1, &buildAs[idx].buildInfo, &buildAs[idx].rangeInfo);
514
519 VkMemoryBarrier barrier{};
520 barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
521 barrier.srcAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR;
522 barrier.dstAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR;
523
524 vkCmdPipelineBarrier(
525 cmdBuf,
526 VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR,
527 VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR,
528 0,
529 1,
530 &barrier,
531 0,
532 nullptr,
533 0,
534 nullptr
535 );
536
540 if (queryPool)
541 {
545 m_VulkanState.m_VkFunc.vkCmdWriteAccelerationStructuresPropertiesKHR(
546 cmdBuf,
547 1,
548 &buildAs[idx].buildInfo.dstAccelerationStructure,
549 VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR,
550 queryPool->Get(),
551 queryCnt++
552 );
553 }
554 }
555 }
#define SPICES_PROFILE_ZONE
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.
AccelKHR CreateAcceleration(VkAccelerationStructureCreateInfoKHR &accel) const
Create Acceleration.
VulkanFunctions m_VkFunc
Definition VulkanUtils.h:98