RT descriptors
This commit is contained in:
parent
7b24f52764
commit
e4e7c66808
9 changed files with 160 additions and 59 deletions
|
|
@ -26,6 +26,8 @@ export module Crafter.Graphics:PipelineRTVulkan;
|
|||
import std;
|
||||
import :VulkanDevice;
|
||||
import :DescriptorLayoutVulkan;
|
||||
import :VulkanBuffer;
|
||||
import :Types;
|
||||
|
||||
export namespace Crafter {
|
||||
template <typename Raygen, typename... Shaders>
|
||||
|
|
@ -33,6 +35,12 @@ export namespace Crafter {
|
|||
public:
|
||||
inline static VkPipeline pipeline;
|
||||
inline static VkPipelineLayout pipelineLayout;
|
||||
inline static std::vector<std::uint8_t> shaderHandles;
|
||||
inline static VulkanBuffer<std::uint8_t, true, true, false> sbtBuffer;
|
||||
inline static VkStridedDeviceAddressRegionKHR raygenRegion;
|
||||
inline static VkStridedDeviceAddressRegionKHR missRegion;
|
||||
inline static VkStridedDeviceAddressRegionKHR hitRegion;
|
||||
inline static VkStridedDeviceAddressRegionKHR callableRegion;
|
||||
|
||||
static void Init() {
|
||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo {
|
||||
|
|
@ -71,7 +79,48 @@ export namespace Crafter {
|
|||
.layout = pipelineLayout
|
||||
};
|
||||
|
||||
VulkanDevice::vkCreateRayTracingPipelinesKHR(VulkanDevice::device, {}, {}, 1, &rtPipelineInfo, nullptr, &pipeline);
|
||||
VulkanDevice::CheckVkResult(VulkanDevice::vkCreateRayTracingPipelinesKHR(VulkanDevice::device, {}, {}, 1, &rtPipelineInfo, nullptr, &pipeline));
|
||||
|
||||
std::uint32_t handleSize = VulkanDevice::rayTracingProperties.shaderGroupHandleSize;
|
||||
std::uint32_t handleAlignment = VulkanDevice::rayTracingProperties.shaderGroupHandleAlignment;
|
||||
std::uint32_t baseAlignment = VulkanDevice::rayTracingProperties.shaderGroupBaseAlignment;
|
||||
std::uint32_t groupCount = rtPipelineInfo.groupCount;
|
||||
|
||||
std::size_t dataSize = handleSize * groupCount;
|
||||
shaderHandles.resize(dataSize);
|
||||
VulkanDevice::CheckVkResult(VulkanDevice::vkGetRayTracingShaderGroupHandlesKHR(VulkanDevice::device, pipeline, 0, groupCount, dataSize, shaderHandles.data()));
|
||||
|
||||
std::uint32_t raygenSize = AlignUp(handleSize, handleAlignment);
|
||||
std::uint32_t missSize = AlignUp(handleSize, handleAlignment);
|
||||
std::uint32_t hitSize = AlignUp(handleSize, handleAlignment);
|
||||
std::uint32_t callableSize = 0;
|
||||
|
||||
std::uint32_t raygenOffset = 0;
|
||||
std::uint32_t missOffset = AlignUp(raygenSize, baseAlignment);
|
||||
std::uint32_t hitOffset = AlignUp(missOffset + missSize, baseAlignment);
|
||||
std::uint32_t callableOffset = AlignUp(hitOffset + hitSize, baseAlignment);
|
||||
|
||||
std::size_t bufferSize = callableOffset + callableSize;
|
||||
|
||||
sbtBuffer.Create(VK_BUFFER_USAGE_2_SHADER_BINDING_TABLE_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, bufferSize);
|
||||
|
||||
// Ray generation shader (group 0)
|
||||
std::memcpy(sbtBuffer.value + raygenOffset, shaderHandles.data() + 0 * handleSize, handleSize);
|
||||
raygenRegion.deviceAddress = sbtBuffer.address + raygenOffset;
|
||||
raygenRegion.stride = raygenSize;
|
||||
raygenRegion.size = raygenSize;
|
||||
|
||||
missRegion.deviceAddress = 0;
|
||||
missRegion.stride = 0;
|
||||
missRegion.size = 0;
|
||||
|
||||
hitRegion.deviceAddress = 0;
|
||||
hitRegion.stride = 0;
|
||||
hitRegion.size = 0;
|
||||
|
||||
callableRegion.deviceAddress = 0;
|
||||
callableRegion.stride = 0;
|
||||
callableRegion.size = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue