Commit ef02cbee authored by Lukas Tietze's avatar Lukas Tietze

Anfang von Postprocessing

parent fed15591
......@@ -244,22 +244,26 @@ lib::AppCreateInfo app::VkrtApp::CreateInitInfo() const
{
lib::AppCreateInfo info;
info.shaderTable.raygenShader.type = lib::ShaderType::Raygen_GLSL;
info.shaderTable.raygenShader.type = lib::ShaderType::Raygen;
info.shaderTable.raygenShader.fileType = lib::ShaderFileType::Glsl;
info.shaderTable.raygenShader.path = "./assets/shaders/raygen.rgen";
info.shaderTable.raygenShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo miss;
miss.type = lib::ShaderType::Miss_GLSL;
miss.type = lib::ShaderType::Miss;
miss.fileType = lib::ShaderFileType::Glsl;
miss.path = "./assets/shaders/miss.rmiss";
miss.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo closestHit;
closestHit.type = lib::ShaderType::ClosestHit_GLSL;
closestHit.type = lib::ShaderType::ClosestHit;
closestHit.fileType = lib::ShaderFileType::Glsl;
closestHit.path = "./assets/shaders/closestHitDefault.rchit";
closestHit.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
lib::ShaderInfo shadowMiss;
shadowMiss.type = lib::ShaderType::Miss_GLSL;
shadowMiss.type = lib::ShaderType::Miss;
shadowMiss.fileType = lib::ShaderFileType::Glsl;
shadowMiss.path = "./assets/shaders/shadow.rmiss";
shadowMiss.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
......@@ -267,6 +271,16 @@ lib::AppCreateInfo app::VkrtApp::CreateInitInfo() const
info.shaderTable.missShaders.push_back(miss);
info.shaderTable.missShaders.push_back(shadowMiss);
info.shaderTable.postProcessingFragmentShader.type = lib::ShaderType::Fragment;
info.shaderTable.postProcessingFragmentShader.fileType = lib::ShaderFileType::Glsl;
info.shaderTable.postProcessingFragmentShader.path = "./assets/shaders/post-processing/default.frag.glsl";
info.shaderTable.postProcessingFragmentShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
info.shaderTable.postProcessingVertexShader.type = lib::ShaderType::Fragment;
info.shaderTable.postProcessingVertexShader.fileType = lib::ShaderFileType::Glsl;
info.shaderTable.postProcessingVertexShader.path = "./assets/shaders/post-processing/default.vert.glsl";
info.shaderTable.postProcessingVertexShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
info.validationInfo.useValidationLayers = true;
info.validationInfo.requireValidationLayers = false;
......
......@@ -148,6 +148,10 @@ namespace lib
std::vector<ShaderInfo> closestHitShaders;
std::vector<ShaderInfo> missShaders;
ShaderInfo postProcessingFragmentShader;
ShaderInfo postProcessingVertexShader;
};
/**
......
......@@ -122,8 +122,12 @@ namespace lib
vk::Extent2D swapChainExtent = {};
vk::Format swapChainImageFormat = {};
vk::PipelineLayout pipelineLayout;
vk::Pipeline pipeline;
vk::PipelineLayout rayTracingPipelineLayout;
vk::Pipeline rayTracingPipeline;
vk::PipelineLayout rasterizerPipelineLayout;
vk::Pipeline rasterizerPipeline;
vk::RenderPass rasterizerRenderPass;
vk::CommandPool stagingCommandPool;
vk::CommandPool computeCommandPool;
......@@ -217,11 +221,12 @@ namespace lib
void CreateSurface();
void CreateSwapChain();
void CreateImageViews();
void CreateCommandPool();
void LoadDummyTexture();
bool TryLoadModel();
void CreateUniformBuffers();
void UpdateUniformBuffers(uint32_t imageIndex, lib::time_diff_t timediff);
void UpdateUniformBuffer(uint32_t imageIndex, lib::time_diff_t timediff);
void CreateCommandBuffers();
void CreateSyncObjects();
void CreateAccelerationStructures();
......@@ -229,7 +234,8 @@ namespace lib
void CreateDescriptorPool();
void CreateDescriptorSetLayout();
void CreateDescriptorSets();
bool TryCreatePipeline();
bool TryCreateRayTracingPipeline();
bool TryCreateRasterizerPipeline();
void CreateShaderBindingTable();
void CreateImGuiComponents();
......
......@@ -2,6 +2,7 @@
#include <memory>
#include "VkUtil/Texture.hpp"
#include "GlfwAndVulkan.hpp"
#include "VkUtil/StagedBuffer.hpp"
......@@ -12,12 +13,16 @@ namespace lib
std::unique_ptr<lib::StagedBuffer> ubo;
vk::CommandPool commandPool;
vk::CommandBuffer commandBuffer;
vk::Image swapChainImage;
vk::ImageView swapChainImageView;
vk::Fence inFlightFence;
vk::DescriptorSet descriptorSet;
vk::Image swapChainImage;
vk::ImageView swapChainImageView;
std::unique_ptr<lib::Texture> raytracingTexture;
std::unique_ptr<lib::Texture> raytracingTexture;
vk::Framebuffer raytracingTextureFbo;
std::unique_ptr<lib::Texture> imGuiTexture;
vk::Framebuffer imGuiTextureFbo;
};
} // namespace lib
......@@ -11,37 +11,46 @@ namespace lib
*/
enum class ShaderType
{
/**
* @brief Ein Raygen-Shader der als unkompilierte GLSL-Datei vorliegt.
* @brief Ein Raygen-Shader.
*/
Raygen_GLSL,
Raygen,
/**
* @brief Ein ClosestHit-Shader der als unkompilierte GLSL-Datei vorliegt.
* @brief Ein ClosestHit-Shader.
*/
ClosestHit_GLSL,
ClosestHit,
/**
* @brief Ein Miss-Shader der als unkompilierte GLSL-Datei vorliegt.
* @brief Ein Miss-Shader.
*/
Miss_GLSL,
Miss,
/**
* @brief Ein Raygen-Shader der als kompilierte SPIR_V-Datei vorliegt.
* @brief Ein Fragment-Shader.
*/
Raygen_SPIR_V,
Fragment,
/**
* @brief Ein ClosestHit-Shader der als kompilierte SPIR_V-Datei vorliegt.
* @brief Ein Vertex-Shader.
*/
ClosestHit_SPIR_V,
Vertex,
};
/**
* @brief Eine Auflistung die anzeigt welcher Inhalt in einer Shader-Datei enthalten ist.
*/
enum class ShaderFileType
{
/**
* @brief Ein Miss-Shader der als kompilierte SPIR_V-Datei vorliegt.
* @brief Shader liegt als unkompilierter GLSL-Code vor.
*/
Miss_SPIR_V,
Glsl,
/**
* @brief Shader liegt als vorkompilierter SPIR-V-Bin盲rcode vor.
*/
SpirV,
};
/**
......@@ -97,6 +106,11 @@ namespace lib
*/
ShaderType type;
/**
* @brief Der Dateityp des Shaders.
*/
ShaderFileType fileType;
/**
* @brief Die Informationen zur Kompilierung oder nullptr, falls die Quelledatei bereits eine
* vorkompilierte SPIR-V-Datei ist.
......
......@@ -17,16 +17,17 @@ namespace lib
class Texture
{
private:
CgContext *parent;
vk::Format format;
vk::Image image;
vk::ImageView view;
vk::DeviceMemory memory;
vk::Sampler sampler;
protected:
static constexpr vk::Format DefaultFormat = vk::Format::eR8G8B8A8Srgb;
CgContext *parent;
protected:
virtual void LoadData(uint32_t width, uint32_t height, const void *data, uint8_t pixelByteCount);
public:
......
......@@ -115,7 +115,7 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
this->CreateDescriptorPool();
this->CreateAccelerationStructures();
this->CreateDescriptorSets();
this->shadersLoaded = this->TryCreatePipeline();
this->shadersLoaded = this->TryCreateRayTracingPipeline() && this->TryCreateRasterizerPipeline();
if (shadersLoaded)
{
......@@ -231,16 +231,16 @@ void lib::CgContext::CleanupSwapChain()
this->shaderBindingTableBuffer = nullptr;
}
if (this->pipeline)
if (this->rayTracingPipeline)
{
this->logicalDevice.destroyPipeline(this->pipeline);
this->pipeline = nullptr;
this->logicalDevice.destroyPipeline(this->rayTracingPipeline);
this->rayTracingPipeline = nullptr;
}
if (this->pipelineLayout)
if (this->rayTracingPipelineLayout)
{
this->logicalDevice.destroyPipelineLayout(this->pipelineLayout);
this->pipelineLayout = nullptr;
this->logicalDevice.destroyPipelineLayout(this->rayTracingPipelineLayout);
this->rayTracingPipelineLayout = nullptr;
}
if (this->descriptorPool)
......@@ -317,7 +317,7 @@ void lib::CgContext::RecreateSwapChain()
if (this->modelLoaded)
{
this->CreateDescriptorSets();
this->shadersLoaded = this->TryCreatePipeline();
this->shadersLoaded = this->TryCreateRayTracingPipeline() && this->TryCreateRasterizerPipeline();
if (this->shadersLoaded)
{
......@@ -690,8 +690,8 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
if (this->IsOk())
{
frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eRayTracingNV, this->pipeline);
frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV, this->pipelineLayout,
frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eRayTracingNV, this->rayTracingPipeline);
frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV, this->rayTracingPipelineLayout,
0, frame.descriptorSet, {});
}
......@@ -705,7 +705,7 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
{
frame.ubo->ScheduleTransfer(frame.commandBuffer);
frame.commandBuffer.pushConstants(this->pipelineLayout,
frame.commandBuffer.pushConstants(this->rayTracingPipelineLayout,
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV,
0, sizeof(this->pushConstant),
&this->pushConstant);
......@@ -846,9 +846,7 @@ vk::ShaderModule lib::CgContext::LoadShader(const ShaderInfo &info)
{
lib::CodeBuffer buf;
if (info.type == ShaderType::Raygen_GLSL ||
info.type == ShaderType::Miss_GLSL ||
info.type == ShaderType::ClosestHit_GLSL)
if (info.fileType == ShaderFileType::Glsl)
{
std::string stringBuf;
......@@ -883,7 +881,7 @@ vk::ShaderModule lib::CgContext::LoadShader(const ShaderInfo &info)
return this->logicalDevice.createShaderModule(createInfo);
}
void lib::CgContext::UpdateUniformBuffers(uint32_t imageIndex, lib::time_diff_t delta)
void lib::CgContext::UpdateUniformBuffer(uint32_t imageIndex, lib::time_diff_t delta)
{
this->camera.UpdateMatrices();
this->frames[imageIndex].ubo->BufferDataHostOnly(SceneDescription{
......@@ -926,7 +924,7 @@ void lib::CgContext::DrawFrame(lib::time_diff_t delta)
auto imageIndex = nextImageResult.value;
this->UpdateUniformBuffers(imageIndex, delta);
this->UpdateUniformBuffer(imageIndex, delta);
if (this->frames[imageIndex].inFlightFence)
{
......@@ -1127,7 +1125,7 @@ void lib::CgContext::CreateUniformBuffers()
frame.ubo->AllocateFor<SceneDescription>();
this->SetObjectName(frame.ubo->GetHostBufferHandle(), name + "[Host]");
this->SetObjectName(frame.ubo->GetDeviceBufferHandle(), name + "[Device]");
this->UpdateUniformBuffers(i, time_diff_t());
this->UpdateUniformBuffer(i, time_diff_t());
i++;
}
......@@ -1403,7 +1401,30 @@ void lib::CgContext::CreateDescriptorSets()
Log("Successfully created raytracing descriptor set!");
}
bool lib::CgContext::TryCreatePipeline()
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;
// vk::PipelineLayoutCreateInfo layoutCreateInfo;
// this->rasterizerPipelineLayout = this->logicalDevice.createPipelineLayout(layoutCreateInfo);
// vk::GraphicsPipelineCreateInfo createInfo;
// this->rasterizerPipeline = this->logicalDevice.createGraphicsPipeline(nullptr, createInfo);
return success;
}
bool lib::CgContext::TryCreateRayTracingPipeline()
{
auto raygenModule = this->LoadShader(this->appInfo.shaderTable.raygenShader);
auto success = static_cast<bool>(raygenModule);
......@@ -1504,7 +1525,7 @@ bool lib::CgContext::TryCreatePipeline()
pipelineLayoutCreateInfo.pushConstantRangeCount = 1;
pipelineLayoutCreateInfo.pPushConstantRanges = &pushConstantRange;
this->pipelineLayout = this->logicalDevice.createPipelineLayout(pipelineLayoutCreateInfo);
this->rayTracingPipelineLayout = this->logicalDevice.createPipelineLayout(pipelineLayoutCreateInfo);
vk::RayTracingPipelineCreateInfoNV pipelineCreateInfo;
pipelineCreateInfo.stageCount = static_cast<uint32_t>(stageCreateInfos.size());
......@@ -1512,9 +1533,9 @@ bool lib::CgContext::TryCreatePipeline()
pipelineCreateInfo.groupCount = static_cast<uint32_t>(groupInfos.size());
pipelineCreateInfo.pGroups = groupInfos.data();
pipelineCreateInfo.maxRecursionDepth = this->physicalDeviceInfo.GetRaytracingProperties().maxRecursionDepth;
pipelineCreateInfo.layout = this->pipelineLayout;
pipelineCreateInfo.layout = this->rayTracingPipelineLayout;
this->pipeline = this->logicalDevice.createRayTracingPipelinesNV(vk::PipelineCache(), pipelineCreateInfo)[0];
this->rayTracingPipeline = this->logicalDevice.createRayTracingPipelinesNV(vk::PipelineCache(), pipelineCreateInfo)[0];
Log("Successfully created raytracing pipeline!");
success = true;
......@@ -1553,7 +1574,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->pipeline, 0, this->shaderOffsets.count,
this->logicalDevice.getRayTracingShaderGroupHandlesNV(this->rayTracingPipeline, 0, this->shaderOffsets.count,
sbtSize, sbtBuf.data());
auto [stagingBuffer, finalBuffer] = this->CreateStagingBuffers(vk::BufferUsageFlagBits::eRayTracingNV);
......
......@@ -107,18 +107,18 @@ namespace
{
switch (type)
{
case lib::ShaderType::Raygen_GLSL:
case lib::ShaderType::Raygen:
return shaderc_shader_kind::shaderc_raygen_shader;
case lib::ShaderType::ClosestHit_GLSL:
case lib::ShaderType::ClosestHit:
return shaderc_shader_kind::shaderc_closesthit_shader;
case lib::ShaderType::Miss_GLSL:
case lib::ShaderType::Miss:
return shaderc_shader_kind::shaderc_miss_shader;
case lib::ShaderType::Miss_SPIR_V:
case lib::ShaderType::Raygen_SPIR_V:
case lib::ShaderType::ClosestHit_SPIR_V:
case lib::ShaderType::Fragment:
return shaderc_shader_kind::shaderc_fragment_shader;
case lib::ShaderType::Vertex:
return shaderc_shader_kind::shaderc_vertex_shader;
default:
throw std::runtime_error("No valid shader_kind could be found!");
break;
}
}
} // namespace
......
......@@ -3,8 +3,8 @@
#include "stb_image.h"
#include "VkUtil/VkUtil.hpp"
lib::Texture::Texture(CgContext *parent, uint32_t width, uint32_t height, vk::Format format = DefaultFormat) : parent(parent),
format(format)
lib::Texture::Texture(CgContext *parent, uint32_t width, uint32_t height, vk::Format format) : parent(parent),
format(format)
{
this->LoadData(width, height, nullptr, 0);
}
......
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