Implemented KRRenderGraphBlackFrame

This commit is contained in:
2024-03-10 17:52:13 -07:00
parent fa96ffefdf
commit a5780cea2b
5 changed files with 131 additions and 17 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);
};

View File

@@ -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<KRRenderGraph>(context))
, m_blackFrameRenderGraph(std::make_unique<KRRenderGraph>(context))
, m_blackFrameRenderGraph(std::make_unique<KRRenderGraphBlackFrame>(context))
, m_swapChain(std::make_unique<KRSwapchain>(context))
, m_surfaceFormat{}
{
}
@@ -143,8 +145,8 @@ KrResult KRSurface::createSwapChain()
std::unique_ptr<KRDevice>& 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;
}

View File

@@ -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<KRRenderGraph> m_renderGraph;
std::unique_ptr<KRRenderGraph> m_blackFrameRenderGraph;
std::unique_ptr<KRRenderGraphBlackFrame> m_blackFrameRenderGraph;
VkSurfaceFormatKHR m_surfaceFormat;
};