Commit b8d74483 authored by Lukas Tietze's avatar Lukas Tietze

Aufteilung in Raster/Ray

parent ef02cbee
#version 460
#extension GL_GOOGLE_include_directive : enable
int main() {
void main() {
}
\ No newline at end of file
#version 460
#extension GL_GOOGLE_include_directive : enable
int main() {
void main() {
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
#include "Core/Camera.hpp"
#include "Core/DeviceInfo.hpp"
#include "Core/Frame.hpp"
#include "Core/RenderStep.hpp"
#include "Util/GenericVertex.hpp"
#include "Util/NameList.hpp"
#include "VkUtil/BottomLevelAccelerationStructure.hpp"
......@@ -119,15 +120,11 @@ namespace lib
vk::DebugUtilsMessengerEXT debugMessenger;
vk::SurfaceKHR surface;
vk::SwapchainKHR swapChain;
vk::Extent2D swapChainExtent = {};
vk::Format swapChainImageFormat = {};
vk::Extent2D swapChainExtent;
vk::Format swapChainImageFormat;
vk::PipelineLayout rayTracingPipelineLayout;
vk::Pipeline rayTracingPipeline;
vk::PipelineLayout rasterizerPipelineLayout;
vk::Pipeline rasterizerPipeline;
vk::RenderPass rasterizerRenderPass;
RenderStep raytracingStep;
RenderStep rasterizationStep;
vk::CommandPool stagingCommandPool;
vk::CommandPool computeCommandPool;
......@@ -168,8 +165,6 @@ namespace lib
std::vector<GeometryInstance> geometryInstances;
std::unique_ptr<TopLevelAccelerationStructure> topLevelAS;
std::vector<BottomLevelAccelerationStructure> bottomLevelAS;
vk::DescriptorPool descriptorPool;
vk::DescriptorSetLayout descriptorSetLayout;
struct
{
......@@ -231,9 +226,20 @@ namespace lib
void CreateSyncObjects();
void CreateAccelerationStructures();
void CreateTopLevelAS(const std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4>> &instances, vk::CommandBuffer commandBuffer, bool updateOnly);
void CreateDescriptorPool();
void CreateDescriptorSetLayout();
void CreateDescriptorPools();
void CreateRasterizationDescriptorPool();
void CreateRaytracingDescriptorPool();
void CreateDescriptorSetLayouts();
void CreateRasterizationDescriptorSetLayout();
void CreateRaytracingDescriptorSetLayout();
void CreateDescriptorSets();
void CreateRasterizationDescriptorSets();
void CreateRaytracingDescriptorSets();
bool TryCreatePipelines();
bool TryCreateRayTracingPipeline();
bool TryCreateRasterizerPipeline();
void CreateShaderBindingTable();
......
#pragma once
#include "GlfwAndVulkan.hpp"
namespace lib
{
struct RenderStep
{
vk::PipelineLayout pipelineLayout;
vk::Pipeline pipeline;
vk::DescriptorSetLayout descriptorSetLayout;
vk::DescriptorPool descriptorPool;
std::vector<vk::DescriptorSet> descriptorSets;
vk::RenderPass renderPass;
};
} // namespace lib
......@@ -111,11 +111,11 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
if (this->modelLoaded)
{
this->CreateDescriptorSetLayout();
this->CreateDescriptorPool();
this->CreateDescriptorSetLayouts();
this->CreateDescriptorPools();
this->CreateAccelerationStructures();
this->CreateDescriptorSets();
this->shadersLoaded = this->TryCreateRayTracingPipeline() && this->TryCreateRasterizerPipeline();
this->shadersLoaded = this->TryCreatePipelines();
if (shadersLoaded)
{
......@@ -150,9 +150,14 @@ lib::CgContext::~CgContext()
this->dummyTexture.reset();
}
if (this->descriptorSetLayout)
if (this->raytracingStep.descriptorSetLayout)
{
this->logicalDevice.destroyDescriptorSetLayout(this->descriptorSetLayout);
this->logicalDevice.destroyDescriptorSetLayout(this->raytracingStep.descriptorSetLayout);
}
if (this->rasterizationStep.descriptorSetLayout)
{
this->logicalDevice.destroyDescriptorSetLayout(this->rasterizationStep.descriptorSetLayout);
}
for (auto &frame : this->frames)
......@@ -231,22 +236,40 @@ void lib::CgContext::CleanupSwapChain()
this->shaderBindingTableBuffer = nullptr;
}
if (this->rayTracingPipeline)
if (this->raytracingStep.pipeline)
{
this->logicalDevice.destroyPipeline(this->raytracingStep.pipeline);
this->raytracingStep.pipeline = nullptr;
}
if (this->rasterizationStep.pipeline)
{
this->logicalDevice.destroyPipeline(this->rasterizationStep.pipeline);
this->rasterizationStep.pipeline = nullptr;
}
if (this->raytracingStep.pipelineLayout)
{
this->logicalDevice.destroyPipeline(this->rayTracingPipeline);
this->rayTracingPipeline = nullptr;
this->logicalDevice.destroyPipelineLayout(this->raytracingStep.pipelineLayout);
this->raytracingStep.pipelineLayout = nullptr;
}
if (this->rayTracingPipelineLayout)
if (this->rasterizationStep.pipelineLayout)
{
this->logicalDevice.destroyPipelineLayout(this->rayTracingPipelineLayout);
this->rayTracingPipelineLayout = nullptr;
this->logicalDevice.destroyPipelineLayout(this->rasterizationStep.pipelineLayout);
this->rasterizationStep.pipelineLayout = nullptr;
}
if (this->descriptorPool)
if (this->raytracingStep.descriptorPool)
{
this->logicalDevice.destroyDescriptorPool(this->descriptorPool);
this->descriptorPool = nullptr;
this->logicalDevice.destroyDescriptorPool(this->raytracingStep.descriptorPool);
this->raytracingStep.descriptorPool = nullptr;
}
if (this->rasterizationStep.descriptorPool)
{
this->logicalDevice.destroyDescriptorPool(this->rasterizationStep.descriptorPool);
this->rasterizationStep.descriptorPool = nullptr;
}
for (const auto &frame : this->frames)
......@@ -312,12 +335,12 @@ void lib::CgContext::RecreateSwapChain()
}
}
this->CreateDescriptorPool();
this->CreateDescriptorPools();
if (this->modelLoaded)
{
this->CreateDescriptorSets();
this->shadersLoaded = this->TryCreateRayTracingPipeline() && this->TryCreateRasterizerPipeline();
this->shadersLoaded = this->TryCreatePipelines();
if (this->shadersLoaded)
{
......@@ -690,8 +713,8 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
if (this->IsOk())
{
frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eRayTracingNV, this->rayTracingPipeline);
frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV, this->rayTracingPipelineLayout,
frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eRayTracingNV, this->raytracingStep.pipeline);
frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV, this->raytracingStep.pipelineLayout,
0, frame.descriptorSet, {});
}
......@@ -705,7 +728,7 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
{
frame.ubo->ScheduleTransfer(frame.commandBuffer);
frame.commandBuffer.pushConstants(this->rayTracingPipelineLayout,
frame.commandBuffer.pushConstants(this->raytracingStep.pipelineLayout,
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV,
0, sizeof(this->pushConstant),
&this->pushConstant);
......@@ -1154,7 +1177,18 @@ void lib::CgContext::CreateAccelerationStructures()
Log("Successfully created acceleration structures!");
}
void lib::CgContext::CreateDescriptorSetLayout()
void lib::CgContext::CreateDescriptorSetLayouts()
{
this->CreateRasterizationDescriptorSetLayout();
this->CreateRaytracingDescriptorSetLayout();
}
void lib::CgContext::CreateRasterizationDescriptorSetLayout()
{
// TODO
}
void lib::CgContext::CreateRaytracingDescriptorSetLayout()
{
std::vector<vk::DescriptorSetLayoutBinding> layoutBindings;
layoutBindings.reserve(8);
......@@ -1229,12 +1263,23 @@ void lib::CgContext::CreateDescriptorSetLayout()
createInfo.bindingCount = static_cast<uint32_t>(layoutBindings.size());
createInfo.pBindings = layoutBindings.data();
this->descriptorSetLayout = this->logicalDevice.createDescriptorSetLayout(createInfo);
this->raytracingStep.descriptorSetLayout = this->logicalDevice.createDescriptorSetLayout(createInfo);
Log("Successfully created descriptor set layout!");
}
void lib::CgContext::CreateDescriptorPool()
void lib::CgContext::CreateDescriptorPools()
{
this->CreateRasterizationDescriptorPool();
this->CreateRaytracingDescriptorPool();
}
void lib::CgContext::CreateRasterizationDescriptorPool()
{
// TODO
}
void lib::CgContext::CreateRaytracingDescriptorPool()
{
auto count = static_cast<uint32_t>(this->frames.size());
std::vector<vk::DescriptorPoolSize> sizes{
......@@ -1261,16 +1306,27 @@ void lib::CgContext::CreateDescriptorPool()
createInfo.pPoolSizes = sizes.data();
createInfo.maxSets = static_cast<uint32_t>(count);
this->descriptorPool = this->logicalDevice.createDescriptorPool(createInfo);
this->raytracingStep.descriptorPool = this->logicalDevice.createDescriptorPool(createInfo);
}
void lib::CgContext::CreateDescriptorSets()
{
this->CreateRaytracingDescriptorSets();
this->CreateRasterizationDescriptorSets();
}
void lib::CgContext::CreateRasterizationDescriptorSets()
{
// TODO
}
void lib::CgContext::CreateRaytracingDescriptorSets()
{
auto count = static_cast<uint32_t>(this->frames.size());
std::vector<vk::DescriptorSetLayout> layouts(count, this->descriptorSetLayout);
std::vector<vk::DescriptorSetLayout> layouts(count, this->raytracingStep.descriptorSetLayout);
vk::DescriptorSetAllocateInfo allocateInfo;
allocateInfo.descriptorPool = this->descriptorPool;
allocateInfo.descriptorPool = this->raytracingStep.descriptorPool;
allocateInfo.pSetLayouts = layouts.data();
allocateInfo.descriptorSetCount = count;
......@@ -1401,18 +1457,26 @@ void lib::CgContext::CreateDescriptorSets()
Log("Successfully created raytracing descriptor set!");
}
bool lib::CgContext::TryCreatePipelines()
{
return this->TryCreateRasterizerPipeline() &&
this->TryCreateRayTracingPipeline();
}
bool lib::CgContext::TryCreateRasterizerPipeline()
{
auto success = true;
auto vertexModule = this->LoadShader(this->appInfo.shaderTable.postProcessingVertexShader);
success = success && vertexModule;
auto fragmentModule = this->LoadShader(this->appInfo.shaderTable.postProcessingFragmentShader);
success = success && vertexModule;
// TODO
// vk::PipelineLayoutCreateInfo layoutCreateInfo;
// this->rasterizerPipelineLayout = this->logicalDevice.createPipelineLayout(layoutCreateInfo);
......@@ -1521,11 +1585,11 @@ bool lib::CgContext::TryCreateRayTracingPipeline()
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
pipelineLayoutCreateInfo.setLayoutCount = 1;
pipelineLayoutCreateInfo.pSetLayouts = &this->descriptorSetLayout;
pipelineLayoutCreateInfo.pSetLayouts = &this->raytracingStep.descriptorSetLayout;
pipelineLayoutCreateInfo.pushConstantRangeCount = 1;
pipelineLayoutCreateInfo.pPushConstantRanges = &pushConstantRange;
this->rayTracingPipelineLayout = this->logicalDevice.createPipelineLayout(pipelineLayoutCreateInfo);
this->raytracingStep.pipelineLayout = this->logicalDevice.createPipelineLayout(pipelineLayoutCreateInfo);
vk::RayTracingPipelineCreateInfoNV pipelineCreateInfo;
pipelineCreateInfo.stageCount = static_cast<uint32_t>(stageCreateInfos.size());
......@@ -1533,9 +1597,9 @@ bool lib::CgContext::TryCreateRayTracingPipeline()
pipelineCreateInfo.groupCount = static_cast<uint32_t>(groupInfos.size());
pipelineCreateInfo.pGroups = groupInfos.data();
pipelineCreateInfo.maxRecursionDepth = this->physicalDeviceInfo.GetRaytracingProperties().maxRecursionDepth;
pipelineCreateInfo.layout = this->rayTracingPipelineLayout;
pipelineCreateInfo.layout = this->raytracingStep.pipelineLayout;
this->rayTracingPipeline = this->logicalDevice.createRayTracingPipelinesNV(vk::PipelineCache(), pipelineCreateInfo)[0];
this->raytracingStep.pipeline = this->logicalDevice.createRayTracingPipelinesNV(vk::PipelineCache(), pipelineCreateInfo)[0];
Log("Successfully created raytracing pipeline!");
success = true;
......@@ -1574,7 +1638,7 @@ void lib::CgContext::CreateShaderBindingTable()
uint32_t sbtSize = static_cast<uint32_t>(this->shaderOffsets.count * this->physicalDeviceInfo.GetRaytracingProperties().shaderGroupHandleSize);
std::vector<uint8_t> sbtBuf(sbtSize);
this->logicalDevice.getRayTracingShaderGroupHandlesNV(this->rayTracingPipeline, 0, this->shaderOffsets.count,
this->logicalDevice.getRayTracingShaderGroupHandlesNV(this->raytracingStep.pipeline, 0, this->shaderOffsets.count,
sbtSize, sbtBuf.data());
auto [stagingBuffer, finalBuffer] = this->CreateStagingBuffers(vk::BufferUsageFlagBits::eRayTracingNV);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment