Render graph, graphics system and pipeline library changes lel

Solved errors
Graphics system AddMaterial now takes in a subpass
Pipeline library now stored in render graph node instead since pipelines have to be compatible with a renderpass.
Renderers now bind render graphs instead of storing them
This commit is contained in:
Brandon Mak 2022-09-18 15:23:10 +08:00
parent 8c30e656f7
commit ec40754eb9
6 changed files with 82 additions and 39 deletions

View File

@ -96,7 +96,11 @@ namespace SHADE
- Render graph in renderers - Render graph in renderers
- Render graph command buffer semaphores - Render graph command buffer semaphores
- Default vertex input state - Default vertex input state
- Global descriptor set layouts
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
ConfigureGlobalDescLayouts();
ConfigureDefaultVertexInputState();
// Set Up Cameras // Set Up Cameras
screenCamera = resourceManager.Create<SHCamera>(); screenCamera = resourceManager.Create<SHCamera>();
screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f));
@ -108,21 +112,11 @@ namespace SHADE
// Create Default Viewport // Create Default Viewport
defaultViewport = AddViewport(vk::Viewport(0.0f, 0.0f, window->GetWindowSize().first, window->GetWindowSize().second, 0.0f, 1.0f)); defaultViewport = AddViewport(vk::Viewport(0.0f, 0.0f, window->GetWindowSize().first, window->GetWindowSize().second, 0.0f, 1.0f));
// Create Debug Renderers
debugScreenRenderer = defaultViewport->AddRenderer(resourceManager,);
debugScreenRenderer->SetCamera(screenCamera);
debugWorldRenderer = defaultViewport->AddRenderer(resourceManager, );
debugWorldRenderer->SetCamera(worldCamera);
// Add world renderer to default viewport
worldRenderer = defaultViewport->AddRenderer(resourceManager, );
worldRenderer->SetCamera(worldCamera);
// Get render graph from default viewport world renderer // Get render graph from default viewport world renderer
auto worldRenderGraph = worldRenderer->GetRenderGraph(); auto worldRenderGraph = resourceManager.Create<SHRenderGraph>();
// Initialize world render graph // Initialize world render graph
worldRenderGraph->Init(device, swapchain); worldRenderGraph->Init(device, swapchain, &defaultVertexInputState, &globalDescSetLayouts);
worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
@ -152,10 +146,17 @@ namespace SHADE
semaHandle = device->CreateSemaphore(); semaHandle = device->CreateSemaphore();
} }
// Create Debug Renderers
debugScreenRenderer = defaultViewport->AddRenderer(resourceManager, worldRenderGraph);
debugScreenRenderer->SetCamera(screenCamera);
debugWorldRenderer = defaultViewport->AddRenderer(resourceManager, worldRenderGraph);
debugWorldRenderer->SetCamera(worldCamera);
// Add world renderer to default viewport
worldRenderer = defaultViewport->AddRenderer(resourceManager, worldRenderGraph);
worldRenderer->SetCamera(worldCamera);
ConfigureDefaultVertexInputState();
pipelineLibrary.Init(device, &defaultVertexInputState, &globalDescSetLayouts);
} }
/***************************************************************************/ /***************************************************************************/
@ -325,19 +326,13 @@ namespace SHADE
{ {
// Retrieve pipeline from pipeline storage or create if unavailable // Retrieve pipeline from pipeline storage or create if unavailable
auto shaderPair = std::make_pair(vertShader, fragShader); auto shaderPair = std::make_pair(vertShader, fragShader);
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetDrawPipline(shaderPair);
if (!pipeline)
{
pipeline = pipelineLibrary.CreateDrawPipeline
(
shaderPair,
subpass->GetParentNode()->GetRenderpass(),
subpass->GetIndex()
);
}
// Create material // Create material
auto mat = resourceManager.Create<SHMaterial>(); auto mat = resourceManager.Create<SHMaterial>();
auto renderGraphNode = subpass->GetParentNode();
auto pipeline = renderGraphNode->GetOrCreatePipeline(std::make_pair(vertShader, fragShader), subpass->GetIndex());
mat->SetPipeline(pipeline); mat->SetPipeline(pipeline);
return mat; return mat;

View File

@ -24,7 +24,6 @@ of DigiPen Institute of Technology is prohibited.
#include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHSystemRoutine.h"
#include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h"
#include "Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h"
#include "Graphics/RenderGraph/SHRenderGraph.h" #include "Graphics/RenderGraph/SHRenderGraph.h"
namespace SHADE namespace SHADE
@ -155,7 +154,6 @@ namespace SHADE
// Not Owned Resources // Not Owned Resources
SHWindow* window; SHWindow* window;
SHPipelineLibrary pipelineLibrary;
std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts; std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts;

View File

@ -18,6 +18,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Tools/SHLogger.h" #include "Tools/SHLogger.h"
#include "SHRenderer.h" #include "SHRenderer.h"
#include "Resource/ResourceLibrary.h" #include "Resource/ResourceLibrary.h"
#include "Graphics/RenderGraph/SHRenderGraph.h"
namespace SHADE namespace SHADE
{ {

View File

@ -29,6 +29,7 @@ namespace SHADE
class SHVkLogicalDevice; class SHVkLogicalDevice;
class SHVkImageView; class SHVkImageView;
class ResourceManager; class ResourceManager;
class SHRenderGraph;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Type Definitions */ /* Type Definitions */

View File

@ -209,10 +209,11 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
SHRenderGraphNode::SHSubpass::SHSubpass(Handle<SHRenderGraphNode> const& parent, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept SHRenderGraphNode::SHSubpass::SHSubpass(Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
: resourceAttachmentMapping{ mapping } : resourceAttachmentMapping{ mapping }
, ptrToResources{ resources } , ptrToResources{ resources }
, parentNode{ parent } , parentNode{ parent }
, subpassIndex {index}
{ {
} }
@ -366,6 +367,11 @@ namespace SHADE
return parentNode; return parentNode;
} }
SHADE::SHSubPassIndex SHRenderGraphNode::SHSubpass::GetIndex() const noexcept
{
return subpassIndex;
}
/***************************************************************************/ /***************************************************************************/
/*! /*!
@ -433,7 +439,7 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
SHRenderGraphNode::SHRenderGraphNode(ResourceManager& rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<Handle<SHRenderGraphResource>> attRes, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept SHRenderGraphNode::SHRenderGraphNode(ResourceManager& rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<Handle<SHRenderGraphResource>> attRes, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources, SHVertexInputState const* defaultViState, std::vector<Handle<SHVkDescriptorSetLayout>> const* globalLayouts) noexcept
: logicalDeviceHdl{ logicalDevice } : logicalDeviceHdl{ logicalDevice }
, renderpass{} , renderpass{}
, framebuffers{} , framebuffers{}
@ -447,6 +453,9 @@ namespace SHADE
, resourceManager{ rm } , resourceManager{ rm }
, ptrToResources{ resources } , ptrToResources{ resources }
{ {
// pipeline library initialization
pipelineLibrary.Init(logicalDeviceHdl, defaultViState, globalLayouts);
attachmentDescriptions.resize(attResources.size()); attachmentDescriptions.resize(attResources.size());
bool containsSwapchainImage = false; bool containsSwapchainImage = false;
@ -545,7 +554,7 @@ namespace SHADE
} }
// Add subpass to container and create mapping for it // Add subpass to container and create mapping for it
subpasses.emplace_back(resourceManager.Create<SHSubpass>(GetHandle(), &resourceAttachmentMapping, ptrToResources)); subpasses.emplace_back(resourceManager.Create<SHSubpass>(GetHandle(), subpasses.size(), &resourceAttachmentMapping, ptrToResources));
subpassIndexing.try_emplace(subpassName, static_cast<uint32_t>(subpasses.size()) - 1u); subpassIndexing.try_emplace(subpassName, static_cast<uint32_t>(subpasses.size()) - 1u);
return subpasses.at(subpassIndexing[subpassName]); return subpasses.at(subpassIndexing[subpassName]);
} }
@ -567,6 +576,29 @@ namespace SHADE
commandBuffer->EndRenderpass(); commandBuffer->EndRenderpass();
} }
Handle<SHVkPipeline> SHRenderGraphNode::GetOrCreatePipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, uint32_t subpassIndex) noexcept
{
// verify subpass exists
if (subpassIndex >= subpasses.size() - 1)
{
SHLOG_ERROR("Subpass index passed in is not valid. RenderGraphNode does not have that many passes. ");
return {};
}
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetDrawPipline(vsFsPair);
if (!pipeline)
{
pipeline = pipelineLibrary.CreateDrawPipeline
(
vsFsPair,
renderpass,
subpassIndex
);
}
return pipeline;
}
/***************************************************************************/ /***************************************************************************/
/*! /*!
@ -920,10 +952,12 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHRenderGraph::Init(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain) noexcept void SHRenderGraph::Init(Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, SHVertexInputState const* defaultViState, std::vector<Handle<SHVkDescriptorSetLayout>> const* globalLayouts) noexcept
{ {
logicalDeviceHdl = logicalDevice; logicalDeviceHdl = logicalDevice;
swapchainHdl = swapchain; swapchainHdl = swapchain;
vertexInputState = defaultViState;
globalDescSetLayouts = globalLayouts;
} }
/***************************************************************************/ /***************************************************************************/
@ -1001,7 +1035,7 @@ namespace SHADE
} }
} }
nodes.emplace_back(resourceManager.Create<SHRenderGraphNode>(resourceManager, logicalDeviceHdl, swapchainHdl, std::move(resources), std::move(predecessors), &graphResources)); nodes.emplace_back(resourceManager.Create<SHRenderGraphNode>(resourceManager, logicalDeviceHdl, swapchainHdl, std::move(resources), std::move(predecessors), &graphResources, vertexInputState, globalDescSetLayouts));
nodeIndexing.emplace(nodeName, static_cast<uint32_t>(nodes.size()) - 1u); nodeIndexing.emplace(nodeName, static_cast<uint32_t>(nodes.size()) - 1u);
return nodes.at(nodeIndexing[nodeName]); return nodes.at(nodeIndexing[nodeName]);
} }

View File

@ -4,6 +4,7 @@
#include "Graphics/Renderpass/SHVkRenderpass.h" #include "Graphics/Renderpass/SHVkRenderpass.h"
#include "Resource/ResourceLibrary.h" #include "Resource/ResourceLibrary.h"
#include "SH_API.h" #include "SH_API.h"
#include "Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h"
#include <string> #include <string>
#include <map> #include <map>
@ -85,7 +86,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* CTORS AND DTORS */ /* CTORS AND DTORS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
SHSubpass(Handle<SHRenderGraphNode> const& parent, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources) noexcept; SHSubpass(Handle<SHRenderGraphNode> const& parent, uint32_t index, std::unordered_map<uint64_t, uint32_t> const* mapping, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources) noexcept;
SHSubpass(SHSubpass&& rhs) noexcept; SHSubpass(SHSubpass&& rhs) noexcept;
SHSubpass& operator=(SHSubpass&& rhs) noexcept; SHSubpass& operator=(SHSubpass&& rhs) noexcept;
@ -105,12 +106,15 @@ namespace SHADE
/* GETTERS AND SETTERS */ /* GETTERS AND SETTERS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
Handle<SHRenderGraphNode> const& GetParentNode (void) const noexcept; Handle<SHRenderGraphNode> const& GetParentNode (void) const noexcept;
SHSubPassIndex GetIndex() const noexcept { return 0; } // TODO SHSubPassIndex GetIndex() const noexcept;
private: private:
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
/* PRIVATE MEMBER VARIABLES */ /* PRIVATE MEMBER VARIABLES */
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
//! The index of the subpass in the render graph
uint32_t subpassIndex;
//! The parent renderpass that this subpass belongs to //! The parent renderpass that this subpass belongs to
Handle<SHRenderGraphNode> parentNode; Handle<SHRenderGraphNode> parentNode;
@ -137,6 +141,7 @@ namespace SHADE
//! COMPLEX. //! COMPLEX.
std::vector<std::function<void(Handle<SHVkCommandBuffer>&)>> exteriorDrawCalls; std::vector<std::function<void(Handle<SHVkCommandBuffer>&)>> exteriorDrawCalls;
friend class SHRenderGraphNode; friend class SHRenderGraphNode;
friend class SHRenderGraph; friend class SHRenderGraph;
}; };
@ -185,6 +190,9 @@ namespace SHADE
//! Pointer to resources in the render graph (for getting handle IDs) //! Pointer to resources in the render graph (for getting handle IDs)
std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources; std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* ptrToResources;
//! Every renderpass will require a pipeline library that will contain pipelines compatible with this renderpass
SHPipelineLibrary pipelineLibrary;
//! Whether or not the node has finished execution //! Whether or not the node has finished execution
bool executed; bool executed;
@ -202,7 +210,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* CTORS AND DTORS */ /* CTORS AND DTORS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
SHRenderGraphNode (ResourceManager& rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<Handle<SHRenderGraphResource>> attRes, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept; SHRenderGraphNode (ResourceManager& rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<Handle<SHRenderGraphResource>> attRes, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources, SHVertexInputState const* defaultViState, std::vector<Handle<SHVkDescriptorSetLayout>> const* globalLayouts) noexcept;
SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept; SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept;
SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept; SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept;
@ -211,6 +219,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
Handle<SHSubpass> AddSubpass (std::string subpassName) noexcept; Handle<SHSubpass> AddSubpass (std::string subpassName) noexcept;
void Execute (Handle<SHVkCommandBuffer>& commandBuffer, uint32_t frameIndex) noexcept; void Execute (Handle<SHVkCommandBuffer>& commandBuffer, uint32_t frameIndex) noexcept;
Handle<SHVkPipeline> GetOrCreatePipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, uint32_t subpassIndex) noexcept;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */ /* SETTERS AND GETTERS */
@ -258,6 +267,11 @@ namespace SHADE
//! Command buffers for the render graph //! Command buffers for the render graph
std::vector<Handle<SHVkCommandBuffer>> commandBuffers; std::vector<Handle<SHVkCommandBuffer>> commandBuffers;
//! Default vertex input state for pipeline creation
SHVertexInputState const* vertexInputState;
//! Global descriptor set layouts to use for pipeline creation
std::vector<Handle<SHVkDescriptorSetLayout>> const* globalDescSetLayouts;
public: public:
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
@ -268,7 +282,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* PUBLIC MEMBER FUNCTIONS */ /* PUBLIC MEMBER FUNCTIONS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
void Init (Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain) noexcept; void Init (Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, SHVertexInputState const* defaultViState, std::vector<Handle<SHVkDescriptorSetLayout>> const* globalLayouts) noexcept;
void AddResource (std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast<uint32_t>(-1), uint32_t h = static_cast<uint32_t>(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageCreateFlagBits createFlags = {}); void AddResource (std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast<uint32_t>(-1), uint32_t h = static_cast<uint32_t>(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageCreateFlagBits createFlags = {});
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<std::string> resourceNames, std::initializer_list<std::string> predecessorNodes) noexcept; Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<std::string> resourceNames, std::initializer_list<std::string> predecessorNodes) noexcept;
void Generate (void) noexcept; void Generate (void) noexcept;