79 lines
3 KiB
Text
79 lines
3 KiB
Text
|
|
/*
|
||
|
|
Crafter®.Graphics
|
||
|
|
Copyright (C) 2026 Catcrafts®
|
||
|
|
catcrafts.net
|
||
|
|
|
||
|
|
This library is free software; you can redistribute it and/or
|
||
|
|
modify it under the terms of the GNU Lesser General Public
|
||
|
|
License version 3.0 as published by the Free Software Foundation;
|
||
|
|
|
||
|
|
This library is distributed in the hope that it will be useful,
|
||
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
|
Lesser General Public License for more details.
|
||
|
|
|
||
|
|
You should have received a copy of the GNU Lesser General Public
|
||
|
|
License along with this library; if not, write to the Free Software
|
||
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
|
*/
|
||
|
|
|
||
|
|
module;
|
||
|
|
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||
|
|
#include <vulkan/vulkan.h>
|
||
|
|
#endif
|
||
|
|
export module Crafter.Graphics:PipelineRTVulkan;
|
||
|
|
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||
|
|
import std;
|
||
|
|
import :VulkanDevice;
|
||
|
|
import :DescriptorLayoutVulkan;
|
||
|
|
|
||
|
|
export namespace Crafter {
|
||
|
|
template <typename Raygen, typename... Shaders>
|
||
|
|
class PipelineRTVulkan {
|
||
|
|
public:
|
||
|
|
inline static VkPipeline pipeline;
|
||
|
|
inline static VkPipelineLayout pipelineLayout;
|
||
|
|
|
||
|
|
static void Init() {
|
||
|
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo {
|
||
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||
|
|
.setLayoutCount = sizeof...(Shaders),
|
||
|
|
.pSetLayouts = DescriptorLayoutVulkan<Shaders...>::descriptorSetLayout
|
||
|
|
};
|
||
|
|
|
||
|
|
VulkanDevice::CheckVkResult(vkCreatePipelineLayout(VulkanDevice::device, &pipelineLayoutInfo, nullptr, &pipelineLayout));
|
||
|
|
|
||
|
|
std::array<VkPipelineShaderStageCreateInfo, 1> shaderStages;
|
||
|
|
|
||
|
|
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||
|
|
shaderStages[0].stage = Raygen::_stage;
|
||
|
|
shaderStages[0].module = Raygen::shader;
|
||
|
|
shaderStages[0].pName = Raygen::_entrypoint.value;
|
||
|
|
shaderStages[0].flags = 0;
|
||
|
|
shaderStages[0].pSpecializationInfo = nullptr;
|
||
|
|
shaderStages[0].pNext = nullptr;
|
||
|
|
|
||
|
|
VkRayTracingShaderGroupCreateInfoKHR group {
|
||
|
|
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||
|
|
.generalShader = 0,
|
||
|
|
.closestHitShader = VK_SHADER_UNUSED_KHR,
|
||
|
|
.anyHitShader = VK_SHADER_UNUSED_KHR,
|
||
|
|
.intersectionShader = VK_SHADER_UNUSED_KHR
|
||
|
|
};
|
||
|
|
|
||
|
|
VkRayTracingPipelineCreateInfoKHR rtPipelineInfo{
|
||
|
|
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR,
|
||
|
|
.stageCount = static_cast<std::uint32_t>(shaderStages.size()),
|
||
|
|
.pStages = shaderStages.data(),
|
||
|
|
.groupCount = static_cast<std::uint32_t>(1),
|
||
|
|
.pGroups = &group,
|
||
|
|
.maxPipelineRayRecursionDepth = 1,
|
||
|
|
.layout = pipelineLayout
|
||
|
|
};
|
||
|
|
|
||
|
|
VulkanDevice::vkCreateRayTracingPipelinesKHR(VulkanDevice::device, {}, {}, 1, &rtPipelineInfo, nullptr, &pipeline);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|