vulkan triangle
This commit is contained in:
parent
8b2fd773b1
commit
96b5d1a299
8 changed files with 170 additions and 48 deletions
|
|
@ -30,7 +30,7 @@ import :VulkanBuffer;
|
|||
import :Types;
|
||||
|
||||
export namespace Crafter {
|
||||
template <typename Raygen, typename... Shaders>
|
||||
template <typename Raygen, typename ClosestHit, typename Miss, typename... Shaders>
|
||||
class PipelineRTVulkan {
|
||||
public:
|
||||
inline static VkPipeline pipeline;
|
||||
|
|
@ -51,7 +51,7 @@ export namespace Crafter {
|
|||
|
||||
VulkanDevice::CheckVkResult(vkCreatePipelineLayout(VulkanDevice::device, &pipelineLayoutInfo, nullptr, &pipelineLayout));
|
||||
|
||||
std::array<VkPipelineShaderStageCreateInfo, 1> shaderStages;
|
||||
std::array<VkPipelineShaderStageCreateInfo, 3> shaderStages;
|
||||
|
||||
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
shaderStages[0].stage = Raygen::_stage;
|
||||
|
|
@ -61,20 +61,56 @@ export namespace Crafter {
|
|||
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
|
||||
};
|
||||
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
shaderStages[1].stage = Miss::_stage;
|
||||
shaderStages[1].module = Miss::shader;
|
||||
shaderStages[1].pName = Miss::_entrypoint.value;
|
||||
shaderStages[1].flags = 0;
|
||||
shaderStages[1].pSpecializationInfo = nullptr;
|
||||
shaderStages[1].pNext = nullptr;
|
||||
|
||||
shaderStages[2].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
shaderStages[2].stage = ClosestHit::_stage;
|
||||
shaderStages[2].module = ClosestHit::shader;
|
||||
shaderStages[2].pName = ClosestHit::_entrypoint.value;
|
||||
shaderStages[2].flags = 0;
|
||||
shaderStages[2].pSpecializationInfo = nullptr;
|
||||
shaderStages[2].pNext = nullptr;
|
||||
|
||||
|
||||
std::array<VkRayTracingShaderGroupCreateInfoKHR, 3> groups {{
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||||
.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR,
|
||||
.generalShader = 0,
|
||||
.closestHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.anyHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.intersectionShader = VK_SHADER_UNUSED_KHR
|
||||
},
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||||
.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR,
|
||||
.generalShader = 1,
|
||||
.closestHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.anyHitShader = VK_SHADER_UNUSED_KHR,
|
||||
.intersectionShader = VK_SHADER_UNUSED_KHR
|
||||
},
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
|
||||
.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR,
|
||||
.generalShader = VK_SHADER_UNUSED_KHR,
|
||||
.closestHitShader = 2,
|
||||
.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,
|
||||
.groupCount = static_cast<std::uint32_t>(groups.size()),
|
||||
.pGroups = groups.data(),
|
||||
.maxPipelineRayRecursionDepth = 1,
|
||||
.layout = pipelineLayout
|
||||
};
|
||||
|
|
@ -110,13 +146,15 @@ export namespace Crafter {
|
|||
raygenRegion.stride = raygenSize;
|
||||
raygenRegion.size = raygenSize;
|
||||
|
||||
missRegion.deviceAddress = 0;
|
||||
missRegion.stride = 0;
|
||||
missRegion.size = 0;
|
||||
std::memcpy(sbtBuffer.value + missOffset, shaderHandles.data() + 1 * handleSize, handleSize);
|
||||
missRegion.deviceAddress = sbtBuffer.address + missOffset;
|
||||
missRegion.stride = missSize;
|
||||
missRegion.size = missSize;
|
||||
|
||||
hitRegion.deviceAddress = 0;
|
||||
hitRegion.stride = 0;
|
||||
hitRegion.size = 0;
|
||||
std::memcpy(sbtBuffer.value + hitOffset, shaderHandles.data() + 2 * handleSize, handleSize);
|
||||
hitRegion.deviceAddress = sbtBuffer.address + hitOffset;
|
||||
hitRegion.stride = hitSize;
|
||||
hitRegion.size = hitSize;
|
||||
|
||||
callableRegion.deviceAddress = 0;
|
||||
callableRegion.stride = 0;
|
||||
|
|
|
|||
|
|
@ -311,14 +311,14 @@ export namespace Crafter {
|
|||
VkCommandBuffer StartInit();
|
||||
void FinishInit();
|
||||
|
||||
template <typename Raygen, typename... Shaders>
|
||||
template <typename Raygen, typename Closesthit, typename Miss, typename... Shaders>
|
||||
void SetPipelineRT() {
|
||||
rtPipeline = PipelineRTVulkan<Raygen, Shaders...>::pipeline;
|
||||
rtPipelineLayout = PipelineRTVulkan<Raygen, Shaders...>::pipelineLayout;
|
||||
raygenRegion = PipelineRTVulkan<Raygen, Shaders...>::raygenRegion;
|
||||
missRegion = PipelineRTVulkan<Raygen, Shaders...>::missRegion;
|
||||
hitRegion = PipelineRTVulkan<Raygen, Shaders...>::hitRegion;
|
||||
callableRegion = PipelineRTVulkan<Raygen, Shaders...>::callableRegion;
|
||||
rtPipeline = PipelineRTVulkan<Raygen, Closesthit, Miss, Shaders...>::pipeline;
|
||||
rtPipelineLayout = PipelineRTVulkan<Raygen, Closesthit, Miss, Shaders...>::pipelineLayout;
|
||||
raygenRegion = PipelineRTVulkan<Raygen, Closesthit, Miss, Shaders...>::raygenRegion;
|
||||
missRegion = PipelineRTVulkan<Raygen, Closesthit, Miss, Shaders...>::missRegion;
|
||||
hitRegion = PipelineRTVulkan<Raygen, Closesthit, Miss, Shaders...>::hitRegion;
|
||||
callableRegion = PipelineRTVulkan<Raygen, Closesthit, Miss, Shaders...>::callableRegion;
|
||||
}
|
||||
inline static wl_compositor* compositor = nullptr;
|
||||
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue