From f4082470070ba921bac4e1ffe8339ae3ffb32039 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 19 Sep 2022 15:52:51 +0800 Subject: [PATCH] Linked MeshLibrary to RenderGraph --- .../src/Application/SBApplication.cpp | 3 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 28 +++++++++++++++++++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 27 +++++++++--------- .../MiddleEnd/Interface/SHRenderer.cpp | 4 +-- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 2 +- .../MiddleEnd/Meshes/SHPrimitiveGenerator.cpp | 1 + .../MiddleEnd/Meshes/SHPrimitiveGenerator.h | 12 +++++++- 7 files changed, 58 insertions(+), 19 deletions(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index aa9c2347..d2bcd760 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -59,7 +59,8 @@ namespace Sandbox SHADE::SHScriptEngine::Init(); // Create temp meshes - + SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem); + graphicsSystem->BuildMeshBuffers(); } void SBApplication::Update(void) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 648be460..c26d7576 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -73,6 +73,34 @@ namespace SHADE struct VertexBufferBindings { + /***************************************************************************/ + /*! + \brief + Vertex buffer bindings for the transform matrix buffer. + */ + /***************************************************************************/ + static constexpr uint32_t POSITION = 0; + /***************************************************************************/ + /*! + \brief + Vertex buffer bindings for the transform matrix buffer. + */ + /***************************************************************************/ + static constexpr uint32_t TEX_COORD = 1; + /***************************************************************************/ + /*! + \brief + Vertex buffer bindings for the transform matrix buffer. + */ + /***************************************************************************/ + static constexpr uint32_t NORMAL = 2; + /***************************************************************************/ + /*! + \brief + Vertex buffer bindings for the transform matrix buffer. + */ + /***************************************************************************/ + static constexpr uint32_t TANGENT = 3; /***************************************************************************/ /*! \brief diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 1a4d9306..579ba9a6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -27,6 +27,7 @@ of DigiPen Institute of Technology is prohibited. #include "ECS_Base/Managers/SHComponentManager.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" +#include "SHGraphicsConstants.h" namespace SHADE { @@ -197,6 +198,16 @@ namespace SHADE // semaphore index. This is for render graphs to have semaphores to signal that the next render graph will use to wait on. bool semIndex = 0; + using BufferPair = std::pair, uint32_t>; + const std::initializer_list MESH_DATA = + { + std::make_pair(meshLibrary.GetVertexPositionsBuffer(), SHGraphicsConstants::VertexBufferBindings::POSITION), + std::make_pair(meshLibrary.GetVertexTexCoordsBuffer(), SHGraphicsConstants::VertexBufferBindings::TEX_COORD), + std::make_pair(meshLibrary.GetVertexNormalsBuffer(), SHGraphicsConstants::VertexBufferBindings::NORMAL), + std::make_pair(meshLibrary.GetVertexTangentsBuffer(), SHGraphicsConstants::VertexBufferBindings::TANGENT), + std::make_pair(meshLibrary.GetIndexBuffer(), 0), + }; + // For every viewport for (int vpIndex = 0; vpIndex < static_cast(viewports.size()); ++vpIndex) { @@ -206,7 +217,7 @@ namespace SHADE for (int renIndex = 0; renIndex < static_cast(renderers.size()); ++renIndex) { // Draw first - renderers[renIndex]->Draw(renderContext.GetCurrentFrame()); + renderers[renIndex]->Draw(renderContext.GetCurrentFrame(), MESH_DATA); // get render graph auto rg = renderers[renIndex]->GetRenderGraph(); @@ -388,7 +399,7 @@ namespace SHADE transferCmdBuffer->BeginRecording(); meshLibrary.BuildBuffers(device, transferCmdBuffer); transferCmdBuffer->EndRecording(); - queue->SubmitCommandBuffer({ transferCmdBuffer }); + graphicsQueue->SubmitCommandBuffer({ transferCmdBuffer }); } void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept @@ -418,10 +429,6 @@ namespace SHADE // For global data (generic data and textures) Handle staticGlobalLayout = device->CreateDescriptorSetLayout({genericDataBinding, texturesBinding}); - - - - SHVkDescriptorSetLayout::Binding lightBinding { .Type = vk::DescriptorType::eStorageBufferDynamic, @@ -433,10 +440,6 @@ namespace SHADE // For Dynamic global data (lights) Handle dynamicGlobalLayout = device->CreateDescriptorSetLayout({ lightBinding }); - - - - SHVkDescriptorSetLayout::Binding cameraDataBinding { .Type = vk::DescriptorType::eUniformBufferDynamic, @@ -448,10 +451,6 @@ namespace SHADE // For High frequency global data (camera) Handle cameraDataGlobalLayout = device->CreateDescriptorSetLayout({ cameraDataBinding }); - - - - SHVkDescriptorSetLayout::Binding materialDataBinding { .Type = vk::DescriptorType::eStorageBufferDynamic, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index d2c447d1..37493176 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -40,9 +40,9 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Drawing Functions */ /*-----------------------------------------------------------------------------------*/ - void SHRenderer::Draw(uint32_t frameIndex) noexcept + void SHRenderer::Draw(uint32_t frameIndex, std::initializer_list, uint32_t>> graphScopeBuffers) noexcept { - renderGraph->Execute(frameIndex); + renderGraph->Execute(frameIndex, graphScopeBuffers); } Handle SHRenderer::GetRenderGraph(void) const noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 4b7e354f..459f62ac 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -62,7 +62,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Drawing Functions */ /*-----------------------------------------------------------------------------*/ - void Draw(uint32_t frameIndex) noexcept; + void Draw(uint32_t frameIndex, std::initializer_list, uint32_t>> graphScopeBuffers) noexcept; /*-----------------------------------------------------------------------------*/ /* Setters and Getters */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp index d096da53..36fa0b26 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited. #include "SHPrimitiveGenerator.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h" +#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h index 493d7e35..e338a9d8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -14,17 +14,27 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Math/SHMath.h" #include "SHMeshData.h" +#include "SH_API.h" namespace SHADE { + /*-----------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*-----------------------------------------------------------------------------------*/ + class SHGraphicsSystem; + + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ /*************************************************************************************/ /*! \brief Static class that contains functions for generating 3D primitives. */ /*************************************************************************************/ - class SHPrimitiveGenerator + class SH_API SHPrimitiveGenerator { + public: /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/