Added UI functionality to the Graphics System #232

Merged
Xenosas1337 merged 40 commits from UI_Integration into main 2022-11-20 15:43:34 +08:00
8 changed files with 95 additions and 16 deletions
Showing only changes of commit 71619d0159 - Show all commits

View File

@ -156,6 +156,8 @@ namespace SHADE
worldCamera->SetLookAt(SHVec3(0.0f, 0.0f, 0.0f), SHVec3(0.0f, 0.0f, -2.0f), SHVec3(0.0f, 1.0f, 0.0f));
worldCamera->SetPerspective(90.0f, static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 100.0f);
worldCameraDirector = cameraSystem->CreateDirector();
// Create Default Viewport
worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(window->GetWindowSize().first), static_cast<float>(window->GetWindowSize().second), 0.0f, 1.0f));
@ -169,7 +171,7 @@ namespace SHADE
}
/*-----------------------------------------------------------------------*/
/* SCENE RENDER GRAPH RESOURCES */
/* WORLD RENDER GRAPH RESOURCES */
/*-----------------------------------------------------------------------*/
// Initialize world render graph
worldRenderGraph->Init(device, swapchain, &resourceManager);
@ -180,7 +182,7 @@ namespace SHADE
worldRenderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
worldRenderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
worldRenderGraph->AddResource("Light Layer Indices", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
worldRenderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second);
worldRenderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second);
worldRenderGraph->AddResource("SSAO", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
worldRenderGraph->AddResource("SSAO Blur", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR8Unorm);
@ -257,25 +259,55 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
gBufferNode->AddNodeCompute(deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" });
// Dummy Node to transition scene render graph resource
auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, { "Debug Draw" }); // no predecessors
auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass");
dummySubpass->AddInput("Scene");
{
//// Dummy Node to transition scene render graph resource
//auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, { "Debug Draw" }); // no predecessors
//auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass");
//dummySubpass->AddInput("Scene");
}
/*-----------------------------------------------------------------------*/
/* GENERATE RENDER GRAPH */
/* GENERATE WORLD RENDER GRAPH */
/*-----------------------------------------------------------------------*/
// Generate world render graph
worldRenderGraph->Generate();
/*-----------------------------------------------------------------------*/
/* SCREEN RENDER GRAPH */
/*-----------------------------------------------------------------------*/
// Initialize screen render graph
screenRenderGraph = resourceManager.Create<SHRenderGraph>();
screenRenderGraph->Init(device, swapchain, &resourceManager);
screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Scene");
auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene" }, {});
auto uiSubpass = screenSpaceNode->AddSubpass("UI");
uiSubpass->AddColorOutput("Scene");
{
// Dummy Node to transition scene render graph resource
auto dummyNode = screenRenderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" }); // no predecessors
auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass");
dummySubpass->AddInput("Scene");
}
screenRenderGraph->Generate();
/*-----------------------------------------------------------------------*/
/* BIND RENDER GRAPH TO RENDERER */
/*-----------------------------------------------------------------------*/
// Add world renderer to default viewport
worldRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph);
worldRenderer->SetCamera(worldCamera);
worldRenderer->SetCameraDirector(worldCameraDirector);
// Add screen renderer to default viewport
screenRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph);
screenRenderer->SetCamera(screenCamera);
screenRenderer->SetCameraDirector(worldCameraDirector);
worldRenderer->SetCameraDirector(cameraSystem->CreateDirector());
// Create debug draw pipeline
debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass);
@ -322,7 +354,7 @@ namespace SHADE
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>();
// initialize the text renderer
auto uiNode = worldRenderGraph->GetNode("Screen Space Pass");
//auto uiNode = screenRenderGraph->GetNode("Screen Space Pass");
//textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS);
SHFreetypeInstance::Init();
@ -906,6 +938,7 @@ namespace SHADE
worldRenderGraph->HandleResize(resizeWidth, resizeHeight);
editorRenderGraph->HandleResize(windowDims.first, windowDims.second);
screenRenderGraph->HandleResize(resizeWidth, resizeHeight);
mousePickSystem->HandleResize();
postOffscreenRender->HandleResize();

View File

@ -32,6 +32,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.h"
#include "Graphics/MiddleEnd/Lights/SHLightingSubSystem.h"
#include "Graphics/MiddleEnd/PostProcessing/SHSSAO.h"
#include "Camera/SHCameraDirector.h"
namespace SHADE
{
@ -392,20 +393,20 @@ namespace SHADE
#ifdef SHEDITOR
Handle<SHViewport> editorViewport;
Handle<SHRenderer> editorRenderer;
Handle<SHRenderGraph> editorRenderGraph;
#endif
Handle<SHViewport> worldViewport; // Whole screen
std::vector<Handle<SHViewport>> viewports; // Additional viewports
std::vector<Handle<SHViewport>> viewports; // Additional viewports
// Temp renderers
// Renderers
Handle<SHRenderer> worldRenderer;
Handle<SHRenderer> screenRenderer;
// Temp Cameras
Handle<SHCamera> worldCamera;
Handle<SHCamera> screenCamera;
DirectorHandle worldCameraDirector;
// Built-In Shaders
Handle<SHVkShaderModule> defaultVertShader;
@ -432,6 +433,10 @@ namespace SHADE
// Render Graphs
Handle<SHRenderGraph> worldRenderGraph;
Handle<SHRenderGraph> screenRenderGraph;
#ifdef SHEDITOR
Handle<SHRenderGraph> editorRenderGraph;
#endif
// Sub systems
Handle<SHMousePickSystem> mousePickSystem;

View File

@ -80,6 +80,12 @@ namespace SHADE
{
if (vk::ImageLayout layout = resourceToLink->GetInfoTracker()->GetLayout(node, {}); layout != vk::ImageLayout::eUndefined)
finalLayout = layout;
for (auto& compute : node->nodeComputes)
{
if (vk::ImageLayout layout = resourceToLink->GetInfoTracker()->GetLayout(compute); layout != vk::ImageLayout::eUndefined)
finalLayout = layout;
}
}
renderGraphStorage->graphResources->try_emplace(resourceName, resourceToLink);
@ -588,7 +594,10 @@ namespace SHADE
{
// resize resources
for (auto& [name, resource] : *renderGraphStorage->graphResources)
resource->HandleResize(newWidth, newHeight);
{
if (!renderGraphStorage->nonOwningResourceInitialLayouts.contains (resource.GetId().Raw))
resource->HandleResize(newWidth, newHeight);
}
for (auto& node : nodes)
{

View File

@ -111,7 +111,10 @@ namespace SHADE
* However, because it was eventually necessary that some resources had to be shared and its contents carried over to
* other graphs, the functionality was implemented through a link function in SHRenderGraph.cpp to facilitate this linkage.
* This should ideally be replaced by an implementation more self-contained, perhaps through a higher level class like a canvas
* that manage the resources instead and can facilitate such linking of resources.
* that manage the resources instead and can facilitate such linking of resources. Either that, or we allow only 1 render graph,
* but different matrices (SHRenderer) can be used in different nodes.
* - There are also way too many hash maps created for ease of access. This definitely can be cut down.
* -
*
*/

View File

@ -275,10 +275,18 @@ namespace SHADE
nodeComputeResources.push_back(resource);
}
// need to use for tracking resources
std::vector<Handle<SHRenderGraphResource>> temp (nodeComputeResources);
// Create the subpass compute with the resources
auto nodeCompute = graphStorage->resourceHub->Create<SHRenderGraphNodeCompute>(graphStorage, computeShaderModule, std::move(nodeComputeResources), std::move (dynamicBufferBindings), nodeComputes.empty());
nodeComputes.push_back(nodeCompute);
for (auto& resource : temp)
{
resource->GetInfoTracker()->TrackLayout(nodeCompute);
}
return nodeCompute;
}

View File

@ -42,6 +42,7 @@ namespace SHADE
// save the resources
resources = std::move (subpassComputeResources);
//Get the descriptor set layouts required to allocate. We only want the ones for allocate because
//global descriptors are already bound in the main system.
auto const& graphResourceLayout = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE];

View File

@ -18,6 +18,11 @@ namespace SHADE
}
void SHRenderGraphResource::InfoTracker::TrackLayout(Handle<SHRenderGraphNodeCompute> compute) noexcept
{
computeTracker.emplace (compute.GetId().Raw);
}
vk::ImageLayout SHRenderGraphResource::InfoTracker::GetLayout(Handle<SHRenderGraphNode> node, Handle<SHSubpass> subpass) const noexcept
{
NodeSubpassPair nodeSubpassPair = std::pair(node, subpass);
@ -29,6 +34,14 @@ namespace SHADE
return vk::ImageLayout::eUndefined;
}
vk::ImageLayout SHRenderGraphResource::InfoTracker::GetLayout(Handle<SHRenderGraphNodeCompute> compute) const noexcept
{
if (computeTracker.contains (compute.GetId().Raw))
return vk::ImageLayout::eGeneral;
else
return vk::ImageLayout::eUndefined;
}
/***************************************************************************/
/*!

View File

@ -6,6 +6,7 @@
#include "Resource/SHHandle.h"
#include "Graphics/SHVulkanIncludes.h"
#include "SH_API.h"
#include <unordered_set>
namespace SHADE
{
@ -18,6 +19,7 @@ namespace SHADE
class SHRenderGraphStorage;
class SHRenderGraphNode;
class SHSubpass;
class SHRenderGraphNodeCompute;
static constexpr uint32_t NON_SWAPCHAIN_RESOURCE_INDEX = 0;
@ -33,16 +35,21 @@ namespace SHADE
//! key here is the render graph node and subpass name combined, value is the layout of the resource at that node and subpass
std::unordered_map<std::size_t, vk::ImageLayout> layoutTracker;
//! if a resource is involved in a compute process, record it here
std::unordered_set<uint64_t> computeTracker;
public:
/*-----------------------------------------------------------------------*/
/* PUBLIC MEMBER FUNCTIONS */
/*-----------------------------------------------------------------------*/
void TrackLayout (Handle<SHRenderGraphNode> node, Handle<SHSubpass> subpass, vk::ImageLayout layout) noexcept;
void TrackLayout (Handle<SHRenderGraphNodeCompute> compute) noexcept;
/*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/
vk::ImageLayout GetLayout (Handle<SHRenderGraphNode> node, Handle<SHSubpass> subpass) const noexcept;
vk::ImageLayout GetLayout(Handle<SHRenderGraphNode> node, Handle<SHSubpass> subpass) const noexcept;
vk::ImageLayout GetLayout(Handle<SHRenderGraphNodeCompute> compute) const noexcept;
};
private: