RT pipeline
This commit is contained in:
parent
962cc4b8cb
commit
7b24f52764
8 changed files with 171 additions and 48 deletions
|
|
@ -21,12 +21,11 @@ module;
|
|||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
#include <vulkan/vulkan.h>
|
||||
#endif
|
||||
export module Crafter.Graphics:DescriptorSetVulkan;
|
||||
export module Crafter.Graphics:DescriptorLayoutVulkan;
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
import std;
|
||||
import :VulkanDevice;
|
||||
import :Types;
|
||||
import Crafter.Event;
|
||||
|
||||
export namespace Crafter {
|
||||
struct DescriptorEntry {
|
||||
|
|
@ -34,17 +33,11 @@ export namespace Crafter {
|
|||
bool occured = true;
|
||||
};
|
||||
|
||||
|
||||
template <std::uint32_t PoolCount, typename... Shaders>
|
||||
class DescriptorPool {
|
||||
template <typename... Shaders>
|
||||
class DescriptorLayoutVulkan {
|
||||
public:
|
||||
inline static Event<void> onDescriptorRefresh;
|
||||
inline static std::uint32_t setIndex = 0;
|
||||
inline static std::uint32_t setsCount = 0;
|
||||
inline static std::vector<VkDescriptorSet> sets;
|
||||
inline static VkDescriptorPool descriptorPool[PoolCount] = { VK_NULL_HANDLE };
|
||||
inline static VkDescriptorSetLayout descriptorSetLayout[sizeof...(Shaders)];
|
||||
|
||||
private:
|
||||
template <typename Shader>
|
||||
consteval static void GetOccuringDescriptors(std::array<DescriptorEntry, 20>& types) {
|
||||
for (const DescriptorBinding& binding : Shader::descriptors) {
|
||||
|
|
@ -115,27 +108,7 @@ export namespace Crafter {
|
|||
}
|
||||
|
||||
public:
|
||||
static void BuildPool(std::uint32_t poolIndex) {
|
||||
if(descriptorPool[poolIndex] != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorPool(VulkanDevice::device, descriptorPool[poolIndex], nullptr);
|
||||
}
|
||||
|
||||
std::array<VkDescriptorPoolSize, uniqueDescriptorCount> poolSizes = GetPoolSizes();
|
||||
for(VkDescriptorPoolSize& size : poolSizes) {
|
||||
size.descriptorCount *= setsCount;
|
||||
}
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptorPoolInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.maxSets = static_cast<std::uint32_t>(setsCount),
|
||||
.poolSizeCount = uniqueDescriptorCount,
|
||||
.pPoolSizes = poolSizes.data()
|
||||
};
|
||||
|
||||
VulkanDevice::CheckVkResult(vkCreateDescriptorPool(VulkanDevice::device, &descriptorPoolInfo, nullptr, &descriptorPool[poolIndex]));
|
||||
|
||||
VkDescriptorSetLayout descriptorSetLayout[sizeof...(Shaders)];
|
||||
|
||||
static void Init() {
|
||||
std::uint32_t shaderIndex = 0;
|
||||
|
||||
([&] {
|
||||
|
|
@ -148,20 +121,6 @@ export namespace Crafter {
|
|||
VulkanDevice::CheckVkResult(vkCreateDescriptorSetLayout(VulkanDevice::device, &descriptorLayoutInfoMesh, nullptr, &descriptorSetLayout[shaderIndex++]));
|
||||
}(),
|
||||
...);
|
||||
|
||||
VkDescriptorSetAllocateInfo allocInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
||||
.descriptorPool = descriptorPool[poolIndex],
|
||||
.descriptorSetCount = setsCount,
|
||||
.pSetLayouts = descriptorSetLayout,
|
||||
};
|
||||
|
||||
sets.resize(setsCount);
|
||||
VulkanDevice::CheckVkResult(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, sets.data()));
|
||||
|
||||
setIndex = 0;
|
||||
|
||||
onDescriptorRefresh.Invoke();
|
||||
}
|
||||
};
|
||||
}
|
||||
79
interfaces/Crafter.Graphics-DescriptorPoolVulkan.cppm
Normal file
79
interfaces/Crafter.Graphics-DescriptorPoolVulkan.cppm
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
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:DescriptorPoolVulkan;
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
import std;
|
||||
import :VulkanDevice;
|
||||
import :Types;
|
||||
import :DescriptorLayoutVulkan;
|
||||
import Crafter.Event;
|
||||
|
||||
export namespace Crafter {
|
||||
template <std::uint32_t PoolCount, typename... Shaders>
|
||||
class DescriptorPool {
|
||||
public:
|
||||
inline static Event<void> onDescriptorRefresh;
|
||||
inline static std::uint32_t setIndex = 0;
|
||||
inline static std::uint32_t setsCount = 0;
|
||||
inline static std::vector<VkDescriptorSet> sets;
|
||||
inline static VkDescriptorPool descriptorPool[PoolCount] = { VK_NULL_HANDLE };
|
||||
|
||||
public:
|
||||
static void BuildPool(std::uint32_t poolIndex) {
|
||||
if(descriptorPool[poolIndex] != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorPool(VulkanDevice::device, descriptorPool[poolIndex], nullptr);
|
||||
}
|
||||
|
||||
std::array<VkDescriptorPoolSize, DescriptorLayoutVulkan<Shaders...>::uniqueDescriptorCount> poolSizes = DescriptorLayoutVulkan<Shaders...>::GetPoolSizes();
|
||||
for(VkDescriptorPoolSize& size : poolSizes) {
|
||||
size.descriptorCount *= setsCount;
|
||||
}
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptorPoolInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.maxSets = static_cast<std::uint32_t>(setsCount),
|
||||
.poolSizeCount = DescriptorLayoutVulkan<Shaders...>::uniqueDescriptorCount,
|
||||
.pPoolSizes = poolSizes.data()
|
||||
};
|
||||
|
||||
VulkanDevice::CheckVkResult(vkCreateDescriptorPool(VulkanDevice::device, &descriptorPoolInfo, nullptr, &descriptorPool[poolIndex]));
|
||||
|
||||
VkDescriptorSetAllocateInfo allocInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
||||
.descriptorPool = descriptorPool[poolIndex],
|
||||
.descriptorSetCount = setsCount,
|
||||
.pSetLayouts = DescriptorLayoutVulkan<Shaders...>::descriptorSetLayout,
|
||||
};
|
||||
|
||||
sets.resize(setsCount);
|
||||
VulkanDevice::CheckVkResult(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, sets.data()));
|
||||
|
||||
setIndex = 0;
|
||||
|
||||
onDescriptorRefresh.Invoke();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
79
interfaces/Crafter.Graphics-PipelineRTVulkan.cppm
Normal file
79
interfaces/Crafter.Graphics-PipelineRTVulkan.cppm
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
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
|
||||
|
|
@ -44,6 +44,7 @@ export namespace Crafter {
|
|||
inline static PFN_vkCreateAccelerationStructureKHR vkCreateAccelerationStructureKHR;
|
||||
inline static PFN_vkCmdBuildAccelerationStructuresKHR vkCmdBuildAccelerationStructuresKHR;
|
||||
inline static PFN_vkGetAccelerationStructureDeviceAddressKHR vkGetAccelerationStructureDeviceAddressKHR;
|
||||
inline static PFN_vkCreateRayTracingPipelinesKHR vkCreateRayTracingPipelinesKHR;
|
||||
inline static VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
static void CreateDevice();
|
||||
static void CheckVkResult(VkResult result);
|
||||
|
|
|
|||
|
|
@ -36,8 +36,10 @@ export import :Mesh;
|
|||
export import :VulkanDevice;
|
||||
export import :VulkanTransition;
|
||||
export import :VulkanBuffer;
|
||||
export import :DescriptorSetVulkan;
|
||||
export import :DescriptorPoolVulkan;
|
||||
export import :DescriptorLayoutVulkan;
|
||||
export import :ShaderVulkan;
|
||||
export import :PipelineRTVulkan;
|
||||
export import :RenderingElement3DVulkan;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue