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:
parent
8c30e656f7
commit
ec40754eb9
|
@ -96,7 +96,11 @@ namespace SHADE
|
|||
- Render graph in renderers
|
||||
- Render graph command buffer semaphores
|
||||
- Default vertex input state
|
||||
- Global descriptor set layouts
|
||||
/*-----------------------------------------------------------------------*/
|
||||
ConfigureGlobalDescLayouts();
|
||||
ConfigureDefaultVertexInputState();
|
||||
|
||||
// Set Up Cameras
|
||||
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));
|
||||
|
@ -107,22 +111,12 @@ namespace SHADE
|
|||
|
||||
// Create Default Viewport
|
||||
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
|
||||
auto worldRenderGraph = worldRenderer->GetRenderGraph();
|
||||
auto worldRenderGraph = resourceManager.Create<SHRenderGraph>();
|
||||
|
||||
// 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("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);
|
||||
|
@ -152,10 +146,17 @@ namespace SHADE
|
|||
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
|
||||
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
|
||||
auto mat = resourceManager.Create<SHMaterial>();
|
||||
|
||||
auto renderGraphNode = subpass->GetParentNode();
|
||||
auto pipeline = renderGraphNode->GetOrCreatePipeline(std::make_pair(vertShader, fragShader), subpass->GetIndex());
|
||||
|
||||
mat->SetPipeline(pipeline);
|
||||
|
||||
return mat;
|
||||
|
|
|
@ -24,7 +24,6 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "ECS_Base/System/SHSystem.h"
|
||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||
#include "Graphics/Descriptors/SHVkDescriptorPool.h"
|
||||
#include "Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h"
|
||||
#include "Graphics/RenderGraph/SHRenderGraph.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -155,7 +154,6 @@ namespace SHADE
|
|||
// Not Owned Resources
|
||||
SHWindow* window;
|
||||
|
||||
SHPipelineLibrary pipelineLibrary;
|
||||
|
||||
std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Tools/SHLogger.h"
|
||||
#include "SHRenderer.h"
|
||||
#include "Resource/ResourceLibrary.h"
|
||||
#include "Graphics/RenderGraph/SHRenderGraph.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace SHADE
|
|||
class SHVkLogicalDevice;
|
||||
class SHVkImageView;
|
||||
class ResourceManager;
|
||||
class SHRenderGraph;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
|
|
|
@ -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 }
|
||||
, ptrToResources{ resources }
|
||||
, parentNode{ parent }
|
||||
, subpassIndex {index}
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -366,6 +367,11 @@ namespace SHADE
|
|||
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 }
|
||||
, renderpass{}
|
||||
, framebuffers{}
|
||||
|
@ -447,6 +453,9 @@ namespace SHADE
|
|||
, resourceManager{ rm }
|
||||
, ptrToResources{ resources }
|
||||
{
|
||||
// pipeline library initialization
|
||||
pipelineLibrary.Init(logicalDeviceHdl, defaultViState, globalLayouts);
|
||||
|
||||
attachmentDescriptions.resize(attResources.size());
|
||||
|
||||
bool containsSwapchainImage = false;
|
||||
|
@ -545,7 +554,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// 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);
|
||||
return subpasses.at(subpassIndexing[subpassName]);
|
||||
}
|
||||
|
@ -567,6 +576,29 @@ namespace SHADE
|
|||
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;
|
||||
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);
|
||||
return nodes.at(nodeIndexing[nodeName]);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Graphics/Renderpass/SHVkRenderpass.h"
|
||||
#include "Resource/ResourceLibrary.h"
|
||||
#include "SH_API.h"
|
||||
#include "Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
@ -85,7 +86,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* 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& operator=(SHSubpass&& rhs) noexcept;
|
||||
|
||||
|
@ -100,17 +101,20 @@ namespace SHADE
|
|||
// Runtime functions
|
||||
void Execute (Handle<SHVkCommandBuffer>& commandBuffer) noexcept;
|
||||
void AddExteriorDrawCalls (std::function<void(Handle<SHVkCommandBuffer>&)> const& newDrawCall) noexcept;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* GETTERS AND SETTERS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
Handle<SHRenderGraphNode> const& GetParentNode (void) const noexcept;
|
||||
SHSubPassIndex GetIndex() const noexcept { return 0; } // TODO
|
||||
SHSubPassIndex GetIndex() const noexcept;
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER VARIABLES */
|
||||
/*---------------------------------------------------------------------*/
|
||||
//! The index of the subpass in the render graph
|
||||
uint32_t subpassIndex;
|
||||
|
||||
//! The parent renderpass that this subpass belongs to
|
||||
Handle<SHRenderGraphNode> parentNode;
|
||||
|
||||
|
@ -137,6 +141,7 @@ namespace SHADE
|
|||
//! COMPLEX.
|
||||
std::vector<std::function<void(Handle<SHVkCommandBuffer>&)>> exteriorDrawCalls;
|
||||
|
||||
|
||||
friend class SHRenderGraphNode;
|
||||
friend class SHRenderGraph;
|
||||
};
|
||||
|
@ -185,6 +190,9 @@ namespace SHADE
|
|||
//! Pointer to resources in the render graph (for getting handle IDs)
|
||||
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
|
||||
bool executed;
|
||||
|
||||
|
@ -202,15 +210,16 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* 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& operator= (SHRenderGraphNode&& rhs) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PUBLIC MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
Handle<SHSubpass> AddSubpass (std::string subpassName) noexcept;
|
||||
void Execute (Handle<SHVkCommandBuffer>& commandBuffer, uint32_t frameIndex) noexcept;
|
||||
Handle<SHSubpass> AddSubpass (std::string subpassName) 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 */
|
||||
|
@ -258,6 +267,11 @@ namespace SHADE
|
|||
//! Command buffers for the render graph
|
||||
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:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -268,7 +282,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* 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 = {});
|
||||
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<std::string> resourceNames, std::initializer_list<std::string> predecessorNodes) noexcept;
|
||||
void Generate (void) noexcept;
|
||||
|
|
Loading…
Reference in New Issue