The SBT(buffer) need to have starting groups to be aligned and handles in the group to be aligned.
Get the shader group handles.
Allocate a buffer for storing the SBT.
Helper to retrieve the handle data.
Map the SBT buffer and write in the handles.
Ray Generation.
Miss.
Closest Hit.
The SBT(buffer) need to have starting groups to be aligned and handles in the group to be aligned.
Get the shader group handles.
Allocate a buffer for storing the SBT.
Helper to retrieve the handle data.
Map the SBT buffer and write in the handles.
Ray Generation.
Miss.
Closest Hit.
361 {
363
364 const uint32_t hitCount =
static_cast<uint32_t
>(
m_HitGroups->size());
365
366 const auto handleCount = rgenCount + missCount + hitCount;
368
373
376
379
382
386 const uint32_t dataSize = handleCount * handleSize;
387 std::vector<uint8_t> handles(dataSize);
389 .m_VkFunc
390 .vkGetRayTracingShaderGroupHandlesKHR(
392 pipeline ,
393 0 ,
394 handleCount ,
395 dataSize ,
396 handles.data()
397 ))
398
399
403
406 "SBTBuffer" ,
407 sbtSize ,
408 VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
409 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
410 VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR ,
411 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
412 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
413 );
414
416
420
424 auto getHandle = [&](int i) { return handles.data() + i * handleSize; };
425
429 uint64_t offset = 0;
430 uint32_t handleIdx = 0 ;
431
435 for (uint32_t c = 0; c < rgenCount; c++)
436 {
437 m_RTSBTBuffer->WriteToBuffer(getHandle(handleIdx++), handleSize, offset);
439 }
440
445 for (uint32_t c = 0; c < missCount; c++)
446 {
447 m_RTSBTBuffer->WriteToBuffer(getHandle(handleIdx++), handleSize, offset);
449 }
450
455 for (uint32_t c = 0; c < hitCount; c++)
456 {
457 m_RTSBTBuffer->WriteToBuffer(getHandle(handleIdx++), handleSize, offset);
459 }
460 }
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
static constexpr integral align_up(integral x, size_t a) noexcept
Align up a memory size aligned with specific value.
static VkPhysicalDeviceRayTracingPipelinePropertiesKHR & GetRTPipelineProperties()
Get RayTracingPipelineProperties.
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.
VkStridedDeviceAddressRegionKHR m_MissRegion
Ray Missing Region.
std::unique_ptr< VulkanBuffer > m_RTSBTBuffer
Shader Binding Table Buffer.
std::shared_ptr< std::unordered_map< std::string, uint32_t > > m_HitGroups
Scene ray hit shader groups.
VkStridedDeviceAddressRegionKHR m_HitRegion
Ray Hit Region.
VkStridedDeviceAddressRegionKHR m_CallRegion
Ray Callable Region.
VkStridedDeviceAddressRegionKHR m_RgenRegion
Ray Generation Region.