From a5780cea2bf245bf7a1fd8d7282e2b5870551208 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sun, 10 Mar 2024 17:52:13 -0700 Subject: [PATCH] Implemented KRRenderGraphBlackFrame --- kraken/CMakeLists.txt | 1 + kraken/KRRenderGraphBlackFrame.cpp | 67 ++++++++++++++++++++++++++++++ kraken/KRRenderGraphBlackFrame.h | 44 ++++++++++++++++++++ kraken/KRSurface.cpp | 28 ++++++------- kraken/KRSurface.h | 8 +++- 5 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 kraken/KRRenderGraphBlackFrame.cpp create mode 100644 kraken/KRRenderGraphBlackFrame.h diff --git a/kraken/CMakeLists.txt b/kraken/CMakeLists.txt index 8705aae..4cf3b86 100644 --- a/kraken/CMakeLists.txt +++ b/kraken/CMakeLists.txt @@ -56,6 +56,7 @@ add_source_and_header(KRParticleSystemNewtonian) add_source_and_header(KRPointLight) add_source_and_header(KRPresentationThread) add_source_and_header(KRRenderGraph) +add_source_and_header(KRRenderGraphBlackFrame) add_source_and_header(KRRenderSettings) add_sources(KRResource+blend) # add_source(KRResource+fbx.cpp) # TODO - Locate FBX SDK dependencies diff --git a/kraken/KRRenderGraphBlackFrame.cpp b/kraken/KRRenderGraphBlackFrame.cpp new file mode 100644 index 0000000..8ee0378 --- /dev/null +++ b/kraken/KRRenderGraphBlackFrame.cpp @@ -0,0 +1,67 @@ +// +// KRRenderGraphBlackFrame.cpp +// Kraken Engine +// +// Copyright 2024 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +#include "KRREnderGraphBlackFrame.h" +#include "KRRenderPass.h" +#include "KRSurface.h" +#include "KRDevice.h" + +KRRenderGraphBlackFrame::KRRenderGraphBlackFrame(KRContext& context) + : KRRenderGraph(context) +{ + +} + +KRRenderGraphBlackFrame::~KRRenderGraphBlackFrame() +{ +} + +void KRRenderGraphBlackFrame::initialize(KRSurface &surface) +{ + VkFormat depthImageFormat = VK_FORMAT_UNDEFINED; + KrResult res = KR_SUCCESS; + res = surface.getDevice()->selectDepthFormat(depthImageFormat); + if (res != KR_SUCCESS) { + return res; + } + + int attachment_blackFrameDepth = addAttachment("Composite Depth", depthImageFormat); + int attachment_blackFrameColor = addAttachment("Composite Color", surface.getSurfaceFormat()); + + RenderPassInfo info{}; + info.colorAttachments[0].id = attachment_blackFrameColor; + info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + info.depthAttachment.id = attachment_blackFrameDepth; + info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + info.finalPass = true; + info.type = RenderPassType::RENDER_PASS_BLACK_FRAME; + addRenderPass(*surface.getDevice(), info); +} diff --git a/kraken/KRRenderGraphBlackFrame.h b/kraken/KRRenderGraphBlackFrame.h new file mode 100644 index 0000000..e71528c --- /dev/null +++ b/kraken/KRRenderGraphBlackFrame.h @@ -0,0 +1,44 @@ +// +// KRRenderGraphBlackFrame.h +// Kraken Engine +// +// Copyright 2024 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +#pragma once + +#include "KRRenderGraph.h" + +class KRRenderGraphBlackFrame : public KRRenderGraph +{ +public: + KRRenderGraphBlackFrame(KRContext& context); + ~KRRenderGraphBlackFrame(); + + void initialize(KRSurface& surface); + +}; diff --git a/kraken/KRSurface.cpp b/kraken/KRSurface.cpp index 21231c2..9b36ba9 100644 --- a/kraken/KRSurface.cpp +++ b/kraken/KRSurface.cpp @@ -32,6 +32,7 @@ #include "KRSurface.h" #include "KRSwapchain.h" #include "KRRenderPass.h" +#include "KRRenderGraphBlackFrame.h" using namespace hydra; @@ -46,8 +47,9 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, void* platformH , m_inFlightFences{VK_NULL_HANDLE} , m_frameIndex(0) , m_renderGraph(std::make_unique(context)) - , m_blackFrameRenderGraph(std::make_unique(context)) + , m_blackFrameRenderGraph(std::make_unique(context)) , m_swapChain(std::make_unique(context)) + , m_surfaceFormat{} { } @@ -143,8 +145,8 @@ KrResult KRSurface::createSwapChain() std::unique_ptr& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle); KrResult res = KR_SUCCESS; - VkSurfaceFormatKHR selectedSurfaceFormat{}; - res = device->selectSurfaceFormat(m_surface, selectedSurfaceFormat); + m_surfaceFormat = {}; + res = device->selectSurfaceFormat(m_surface, m_surfaceFormat); if (res != KR_SUCCESS) return res; VkFormat depthImageFormat = VK_FORMAT_UNDEFINED; @@ -177,7 +179,7 @@ KrResult KRSurface::createSwapChain() // ------------------------- int attachment_compositeDepth = m_renderGraph->addAttachment("Composite Depth", depthImageFormat); - int attachment_compositeColor = m_renderGraph->addAttachment("Composite Color", selectedSurfaceFormat.format); + int attachment_compositeColor = m_renderGraph->addAttachment("Composite Color", m_surfaceFormat.format); int attachment_lightAccumulation = m_renderGraph->addAttachment("Light Accumulation", VK_FORMAT_B8G8R8A8_UINT); int attachment_gbuffer = m_renderGraph->addAttachment("GBuffer", VK_FORMAT_B8G8R8A8_UINT); int attachment_shadow_cascades[3]; @@ -291,18 +293,9 @@ KrResult KRSurface::createSwapChain() m_renderGraph->addRenderPass(*device, info); - int attachment_blackFrameDepth = m_blackFrameRenderGraph->addAttachment("Composite Depth", depthImageFormat); - int attachment_blackFrameColor = m_blackFrameRenderGraph->addAttachment("Composite Color", selectedSurfaceFormat.format); + m_blackFrameRenderGraph->initialize(*this); - info.colorAttachments[0].id = attachment_blackFrameColor; - info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; - info.depthAttachment.id = attachment_blackFrameDepth; - info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; - info.finalPass = true; - info.type = RenderPassType::RENDER_PASS_BLACK_FRAME; - m_blackFrameRenderGraph->addRenderPass(*device, info); - - m_swapChain->create(*device, m_surface, selectedSurfaceFormat, depthImageFormat, swapExtent, imageCount, *m_renderGraph->getRenderPass(RenderPassType::RENDER_PASS_FORWARD_OPAQUE)); + m_swapChain->create(*device, m_surface, m_surfaceFormat, depthImageFormat, swapExtent, imageCount, *m_renderGraph->getRenderPass(RenderPassType::RENDER_PASS_FORWARD_OPAQUE)); return KR_SUCCESS; } @@ -370,3 +363,8 @@ void KRSurface::renderBlackFrame(VkCommandBuffer &commandBuffer) { m_blackFrameRenderGraph->render(commandBuffer, *this, nullptr); } + +VkFormat KRSurface::getSurfaceFormat() const +{ + return m_surfaceFormat.format; +} diff --git a/kraken/KRSurface.h b/kraken/KRSurface.h index b3774db..9b31a78 100644 --- a/kraken/KRSurface.h +++ b/kraken/KRSurface.h @@ -33,12 +33,13 @@ #include "KREngine-common.h" #include "KRContext.h" -#include "KRRenderGraph.h" class KRDevice; class KRRenderPass; class KRSwapchain; class KRRenderGraph; +class KRRenderGraphBlackFrame; +enum RenderPassType : uint8_t; class KRSurface : public KRContextObject { @@ -51,6 +52,7 @@ public: hydra::Vector2i getDimensions() const; VkFormat getDepthFormat() const; void renderBlackFrame(VkCommandBuffer &commandBuffer); + VkFormat getSurfaceFormat() const; KRSurface(const KRSurface&) = delete; KRSurface& operator=(const KRSurface&) = delete; @@ -80,5 +82,7 @@ private: void destroySwapChain(); KrResult createSwapChain(); std::unique_ptr m_renderGraph; - std::unique_ptr m_blackFrameRenderGraph; + std::unique_ptr m_blackFrameRenderGraph; + + VkSurfaceFormatKHR m_surfaceFormat; };