Commit 724c772b authored by Lukas Tietze's avatar Lukas Tietze

Aktualisierte Validation Layers aktiviert.

parent 262bb32a
......@@ -97,6 +97,21 @@ namespace lib
* @return const glm::vec3& Die Hintergrundfarbe.
*/
virtual const glm::vec3 &GetClearColor() const = 0;
/**
* @brief Holt einen Wert der angibt, ob PostProcessing aktiviert ist oder nicht.
*
* @return true PostProcessing ist aktiviert.
* @return false PostProcessing ist nicht aktiviert.
*/
virtual bool IsPostProcessingEnabled() const = 0;
/**
* @brief Setzt einen Wert der angibt, ob PostProcessing aktiviert ist oder nicht.
*
* @param value Der neue Wert.
*/
virtual void SetPostProcessingEnabled(bool value) = 0;
};
/**
......@@ -207,6 +222,8 @@ namespace lib
bool show = false;
} imGui;
bool doPostProcessing = true;
void InitRandomGenerators();
void CreateInstance();
void SetupDebugCallbacks();
......@@ -217,6 +234,7 @@ namespace lib
void CreateSwapChain();
void CreateImageViews();
void CreateRasterizationRenderPass();
void CreateRasterizationFrameBuffers();
void CreateCommandPool();
void LoadDummyTexture();
......@@ -308,6 +326,8 @@ namespace lib
const std::array<lib::LightSource, lib::MaxLights> &GetLightSources() const override;
glm::vec3 &GetClearColor() override;
const glm::vec3 &GetClearColor() const override;
bool IsPostProcessingEnabled() const override;
void SetPostProcessingEnabled(bool value) override;
vk::ShaderModule LoadShader(const ShaderInfo &info);
......
......@@ -12,5 +12,6 @@ namespace lib
vk::DescriptorPool descriptorPool;
std::vector<vk::DescriptorSet> descriptorSets;
vk::RenderPass renderPass;
std::vector<vk::Framebuffer> frameBuffers;
};
} // namespace lib
......@@ -104,6 +104,9 @@ namespace lib
this->LoadData(width, height, buf.data(), sizeof(buf.front()), createInfo);
}
Texture(Texture &&) = delete;
Texture(const Texture &) = delete;
~Texture();
const vk::Image &GetHandle() const;
......@@ -111,5 +114,8 @@ namespace lib
const vk::ImageView &GetView() const;
const vk::Sampler &GetSampler() const;
Texture &operator=(Texture &&) = delete;
Texture &operator=(const Texture &) = delete;
}; // namespace lib
} // namespace lib
......@@ -287,4 +287,14 @@ void lib::CgContext::SetObjectName(const vk::Buffer &buffer, const std::string &
void lib::CgContext::SetShowUi(bool show)
{
this->imGui.show = show;
}
\ No newline at end of file
}
bool lib::CgContext::IsPostProcessingEnabled() const
{
return this->doPostProcessing;
}
void lib::CgContext::SetPostProcessingEnabled(bool value)
{
this->doPostProcessing = value;
}
......@@ -34,14 +34,13 @@ using lib::log::Warning;
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;
success = success && fragmentModule;
if (success)
{
......@@ -67,6 +66,8 @@ bool lib::CgContext::TryCreateRasterizerPipeline()
inputAssemblyCreateInfo.primitiveRestartEnable = false;
vk::Viewport viewport;
viewport.x = 0.f;
viewport.y = 0.f;
viewport.width = static_cast<float>(this->swapChainExtent.width);
viewport.height = static_cast<float>(this->swapChainExtent.height);
viewport.minDepth = 0.f;
......@@ -83,10 +84,13 @@ bool lib::CgContext::TryCreateRasterizerPipeline()
viewportStateCreateInfo.pScissors = &scissor;
vk::PipelineRasterizationStateCreateInfo rasterizationStateCreateInfo;
rasterizationStateCreateInfo.cullMode = vk::CullModeFlagBits::eFront;
rasterizationStateCreateInfo.frontFace = vk::FrontFace::eCounterClockwise;
rasterizationStateCreateInfo.lineWidth = 1.f;
rasterizationStateCreateInfo.depthClampEnable = false;
rasterizationStateCreateInfo.rasterizerDiscardEnable = false;
rasterizationStateCreateInfo.polygonMode = vk::PolygonMode::eFill;
rasterizationStateCreateInfo.lineWidth = 1.f;
rasterizationStateCreateInfo.frontFace = vk::FrontFace::eCounterClockwise;
rasterizationStateCreateInfo.cullMode = vk::CullModeFlagBits::eBack;
rasterizationStateCreateInfo.depthBiasEnable = false;
vk::PipelineMultisampleStateCreateInfo multiSampleStageCreateInfo;
multiSampleStageCreateInfo.sampleShadingEnable = false;
......@@ -120,6 +124,7 @@ bool lib::CgContext::TryCreateRasterizerPipeline()
createInfo.pRasterizationState = &rasterizationStateCreateInfo;
createInfo.pMultisampleState = &multiSampleStageCreateInfo;
createInfo.pColorBlendState = &colorBlendStateCreateInfo;
createInfo.renderPass = this->rasterizationStep.renderPass;
createInfo.layout = this->rasterizationStep.pipelineLayout;
const auto result = this->logicalDevice.createGraphicsPipeline(nullptr, createInfo);
......@@ -146,6 +151,8 @@ bool lib::CgContext::TryCreateRasterizerPipeline()
this->logicalDevice.destroyShaderModule(fragmentModule);
}
lib::log::Info("Successfully create rasterization pipeline!");
return success;
}
......@@ -179,6 +186,8 @@ void lib::CgContext::CreateRasterizationDescriptorSets()
this->logicalDevice.updateDescriptorSets(rtImageWrite, {});
}
lib::log::Info("Successfully created rasterization descriptor sets!");
}
void lib::CgContext::CreateRasterizationDescriptorPool()
......@@ -195,6 +204,8 @@ void lib::CgContext::CreateRasterizationDescriptorPool()
createInfo.maxSets = count;
this->rasterizationStep.descriptorPool = this->logicalDevice.createDescriptorPool(createInfo);
lib::log::Info("Successfully created rasterization descriptor pool!");
}
void lib::CgContext::CreateRasterizationDescriptorSetLayout()
......@@ -212,6 +223,8 @@ void lib::CgContext::CreateRasterizationDescriptorSetLayout()
createInfo.pBindings = layoutBindings.data();
this->rasterizationStep.descriptorSetLayout = this->logicalDevice.createDescriptorSetLayout(createInfo);
lib::log::Info("Successfully created rasterization descriptor set layouts!");
}
void lib::CgContext::CreateRasterizationRenderPass()
......@@ -251,4 +264,27 @@ void lib::CgContext::CreateRasterizationRenderPass()
createInfo.pAttachments = &colorAttachment;
this->rasterizationStep.renderPass = this->logicalDevice.createRenderPass(createInfo);
lib::log::Info("Successfully created rasterization render pass!");
}
void lib::CgContext::CreateRasterizationFrameBuffers()
{
const auto count = static_cast<uint32_t>(frames.size());
this->rasterizationStep.frameBuffers.reserve(count);
this->rasterizationStep.frameBuffers.clear();
for (uint32_t i = 0; i < count; i++)
{
vk::FramebufferCreateInfo createInfo;
createInfo.renderPass = this->rasterizationStep.renderPass;
createInfo.attachmentCount = 1;
createInfo.pAttachments = &frames[i].swapChainImageView;
createInfo.width = this->swapChainExtent.width;
createInfo.height = this->swapChainExtent.height;
createInfo.layers = 1;
this->rasterizationStep.frameBuffers.push_back(logicalDevice.createFramebuffer(createInfo));
}
}
\ No newline at end of file
......@@ -103,6 +103,8 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
this->CreateQueues();
this->CreateSwapChain();
this->CreateImageViews();
this->CreateRasterizationRenderPass();
this->CreateRasterizationFrameBuffers();
this->CreateUniformBuffers();
this->CreateCommandPool();
this->LoadDummyTexture();
......@@ -229,6 +231,14 @@ void lib::CgContext::CleanupSwapChain()
this->logicalDevice.freeCommandBuffers(frame.commandPool, frame.commandBuffer);
}
for (auto rasterizationFrameBuffer : this->rasterizationStep.frameBuffers)
{
if (rasterizationFrameBuffer)
{
this->logicalDevice.destroyFramebuffer(rasterizationFrameBuffer);
}
}
if (this->shaderBindingTableBuffer)
{
this->shaderBindingTableBuffer->Destroy();
......@@ -323,6 +333,8 @@ void lib::CgContext::RecreateSwapChain()
this->CreateSwapChain();
this->CreateImageViews();
this->CreateRasterizationRenderPass();
this->CreateRasterizationFrameBuffers();
if (!this->modelLoaded)
{
......@@ -404,17 +416,25 @@ void lib::CgContext::CreateInstance()
if (this->appInfo.validationInfo.useValidationLayers)
{
if (this->CheckLayer("VK_LAYER_LUNARG_standard_validation"))
{
usedLayers.Add("VK_LAYER_LUNARG_standard_validation");
}
else if (this->appInfo.validationInfo.requireValidationLayers)
{
throw CoreInitException("Not all required Layers are available!");
}
else
std::vector<const char *> requiredLayers = {
"VK_LAYER_KHRONOS_validation",
"VK_LAYER_LUNARG_standard_validation",
};
for (auto layer : requiredLayers)
{
Warning("Not all required Layers are available!");
if (this->CheckLayer(layer))
{
usedLayers.Add(layer);
}
else if (this->appInfo.validationInfo.requireValidationLayers)
{
throw CoreInitException("Not all required Layers are available!");
}
else
{
Warning("Not all required Layers are available!");
}
}
}
......@@ -472,11 +492,6 @@ void lib::CgContext::SetupDebugCallbacks()
createInfo.messageSeverity |= vk::DebugUtilsMessageSeverityFlagBitsEXT::eError;
}
if (this->appInfo.loggingInfo.infosEnabled)
{
createInfo.messageSeverity |= vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo;
}
createInfo.messageType = vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation |
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance;
......@@ -748,14 +763,17 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
this->shaderBindingTableBuffer->GetBufferHandle(), 0, 0,
this->swapChainExtent.width, this->swapChainExtent.height, 1);
}
TransitionImageLayout(frame.commandBuffer,
frame.raytracingTexture->GetHandle(), this->swapChainImageFormat,
vk::ImageLayout::eGeneral, vk::ImageLayout::eColorAttachmentOptimal,
vk::PipelineStageFlagBits::eRayTracingShaderNV, vk::PipelineStageFlagBits::eFragmentShader);
if (this->doPostProcessing)
{
TransitionImageLayout(frame.commandBuffer,
frame.raytracingTexture->GetHandle(), this->swapChainImageFormat,
vk::ImageLayout::eGeneral, vk::ImageLayout::eColorAttachmentOptimal,
vk::PipelineStageFlagBits::eRayTracingShaderNV, vk::PipelineStageFlagBits::eFragmentShader);
vk::RenderPassBeginInfo ppBeginInfo;
ppBeginInfo.renderPass = this->rasterizationStep.renderPass;
ppBeginInfo.framebuffer = this->imGui.frameBuffers[imageIndex];
ppBeginInfo.framebuffer = this->rasterizationStep.frameBuffers[imageIndex];
ppBeginInfo.renderArea.offset = {0, 0};
ppBeginInfo.renderArea.extent = this->swapChainExtent;
......
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