ray_tracing_indirect_scissor/hello_vulkan.cpp
void HelloVulkan::createRtDescriptorSet()
{
  // Top-level acceleration structure, usable by both the ray generation and the closest hit (to
  // shoot shadow rays)
  m_rtDescSetLayoutBind.addBinding(RtxBindings::eTlas, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1,
                                   VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR);  // TLAS
  m_rtDescSetLayoutBind.addBinding(RtxBindings::eOutImage, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1,
                                   VK_SHADER_STAGE_RAYGEN_BIT_KHR);  // Output image
  // Lantern buffer
  m_rtDescSetLayoutBind.addBinding(eLanterns, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1,
                                   VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR);
  assert(m_lanternCount > 0);

  m_rtDescPool      = m_rtDescSetLayoutBind.createPool(m_device);
  m_rtDescSetLayout = m_rtDescSetLayoutBind.createLayout(m_device);

  VkDescriptorSetAllocateInfo allocateInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
  allocateInfo.descriptorPool     = m_rtDescPool;
  allocateInfo.descriptorSetCount = 1;
  allocateInfo.pSetLayouts        = &m_rtDescSetLayout;
  vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet);


  VkAccelerationStructureKHR                   tlas = m_rtBuilder.getAccelerationStructure();
  VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
  descASInfo.accelerationStructureCount = 1;
  descASInfo.pAccelerationStructures    = &tlas;
  VkDescriptorImageInfo imageInfo{{}, m_offscreenColor.descriptor.imageView, VK_IMAGE_LAYOUT_GENERAL};
  VkDescriptorBufferInfo lanternBufferInfo{m_lanternIndirectBuffer.buffer, 0, m_lanternCount * sizeof(LanternIndirectEntry)};

  std::vector<VkWriteDescriptorSet> writes;
  writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, RtxBindings::eTlas, &descASInfo));
  writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, RtxBindings::eOutImage, &imageInfo));
  writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, eLanterns, &lanternBufferInfo));
  vkUpdateDescriptorSets(m_device, static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr);
}
//--------------------------------------------------------------------------------------------------
// This descriptor set holds the Acceleration structure, output image, and lanterns array buffer.
//
This descriptor set holds the Acceleration structure, output image, and lanterns array buffer.
This descriptor set holds the Acceleration structure output image and lanterns array buffer .
void HelloVulkan::createRtDescriptorSet()
{
  m_rtDescSetLayoutBind.addBinding(RtxBindings::eTlas, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1,
                                   VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR);  
  m_rtDescSetLayoutBind.addBinding(RtxBindings::eOutImage, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1,
                                   VK_SHADER_STAGE_RAYGEN_BIT_KHR);  
  m_rtDescSetLayoutBind.addBinding(eLanterns, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1,
                                   VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR);
  assert(m_lanternCount > 0);
  m_rtDescPool      = m_rtDescSetLayoutBind.createPool(m_device);
  m_rtDescSetLayout = m_rtDescSetLayoutBind.createLayout(m_device);
  VkDescriptorSetAllocateInfo allocateInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
  allocateInfo.descriptorPool     = m_rtDescPool;
  allocateInfo.descriptorSetCount = 1;
  allocateInfo.pSetLayouts        = &m_rtDescSetLayout;
  vkAllocateDescriptorSets(m_device, &allocateInfo, &m_rtDescSet);
  VkAccelerationStructureKHR                   tlas = m_rtBuilder.getAccelerationStructure();
  VkWriteDescriptorSetAccelerationStructureKHR descASInfo{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
  descASInfo.accelerationStructureCount = 1;
  descASInfo.pAccelerationStructures    = &tlas;
  VkDescriptorImageInfo imageInfo{{}, m_offscreenColor.descriptor.imageView, VK_IMAGE_LAYOUT_GENERAL};
  VkDescriptorBufferInfo lanternBufferInfo{m_lanternIndirectBuffer.buffer, 0, m_lanternCount * sizeof(LanternIndirectEntry)};
  std::vector<VkWriteDescriptorSet> writes;
  writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, RtxBindings::eTlas, &descASInfo));
  writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, RtxBindings::eOutImage, &imageInfo));
  writes.emplace_back(m_rtDescSetLayoutBind.makeWrite(m_rtDescSet, eLanterns, &lanternBufferInfo));
  vkUpdateDescriptorSets(m_device, static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr);
}
void HelloVulkan :: createRtDescriptorSet ( ) { m_rtDescSetLayoutBind . addBinding ( RtxBindings :: eTlas , VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR , 1 , VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR ) ; m_rtDescSetLayoutBind . addBinding ( RtxBindings :: eOutImage , VK_DESCRIPTOR_TYPE_STORAGE_IMAGE , 1 , VK_SHADER_STAGE_RAYGEN_BIT_KHR ) ; m_rtDescSetLayoutBind . addBinding ( eLanterns , VK_DESCRIPTOR_TYPE_STORAGE_BUFFER , 1 , VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR ) ; assert ( m_lanternCount > 0 ) ; m_rtDescPool = m_rtDescSetLayoutBind . createPool ( m_device ) ; m_rtDescSetLayout = m_rtDescSetLayoutBind . createLayout ( m_device ) ; VkDescriptorSetAllocateInfo allocateInfo { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO } ; allocateInfo . descriptorPool = m_rtDescPool ; allocateInfo . descriptorSetCount = 1 ; allocateInfo . pSetLayouts = & m_rtDescSetLayout ; vkAllocateDescriptorSets ( m_device , & allocateInfo , & m_rtDescSet ) ; VkAccelerationStructureKHR tlas = m_rtBuilder . getAccelerationStructure ( ) ; VkWriteDescriptorSetAccelerationStructureKHR descASInfo { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR } ; descASInfo . accelerationStructureCount = 1 ; descASInfo . pAccelerationStructures = & tlas ; VkDescriptorImageInfo imageInfo { { } , m_offscreenColor . descriptor . imageView , VK_IMAGE_LAYOUT_GENERAL } ; VkDescriptorBufferInfo lanternBufferInfo { m_lanternIndirectBuffer . buffer , 0 , m_lanternCount * sizeof ( LanternIndirectEntry ) } ; std :: vector < VkWriteDescriptorSet > writes ; writes . emplace_back ( m_rtDescSetLayoutBind . makeWrite ( m_rtDescSet , RtxBindings :: eTlas , & descASInfo ) ) ; writes . emplace_back ( m_rtDescSetLayoutBind . makeWrite ( m_rtDescSet , RtxBindings :: eOutImage , & imageInfo ) ) ; writes . emplace_back ( m_rtDescSetLayoutBind . makeWrite ( m_rtDescSet , eLanterns , & lanternBufferInfo ) ) ; vkUpdateDescriptorSets ( m_device , static_cast < uint32_t > ( writes . size ( ) ) , writes . data ( ) , 0 , nullptr ) ; }
This descriptor set holds the Acceleration structure, output image, and lanterns array buffer.
This descriptor set holds the Acceleration structure output image and lanterns array buffer .
// Top-level acceleration structure, usable by both the ray generation and the closest hit (to // shoot shadow rays) // TLAS // Output image // Lantern buffer