From 9a5dc52d776f47aaf77478289a6b2d185dc58ad5 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Mon, 5 Dec 2022 23:25:43 +0800 Subject: [PATCH 01/24] Minor fixes to input manager - Pass binding names into functions by const reference instead of by value - Fixed oversight of not being able to modify or read mouse Y positive multiplier for a binding --- SHADE_Engine/src/Input/SHInputManager.cpp | 24 ++++---- SHADE_Engine/src/Input/SHInputManager.h | 70 +++++++++++------------ 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index 4849a772..f6b58a94 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -575,7 +575,7 @@ namespace SHADE } //Only get of largest magnitude - double SHInputManager::GetBindingAxis(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingAxis(std::string const& bindingName, size_t cNum) noexcept { //Over keycodes, prioritise positive for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes) @@ -606,7 +606,7 @@ namespace SHADE return largestMagnitude; } - bool SHInputManager::GetBindingPositiveButton(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingPositiveButton(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -625,7 +625,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingNegativeButton(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingNegativeButton(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -644,7 +644,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingPositiveButtonDown(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingPositiveButtonDown(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -663,7 +663,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingNegativeButtonDown(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingNegativeButtonDown(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -682,7 +682,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingPositiveButtonUp(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingPositiveButtonUp(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -701,7 +701,7 @@ namespace SHADE return false; } - bool SHInputManager::GetBindingNegativeButtonUp(std::string bindingName, size_t cNum) noexcept + bool SHInputManager::GetBindingNegativeButtonUp(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return false; @@ -721,7 +721,7 @@ namespace SHADE } //Fetches longest hold time - double SHInputManager::GetBindingPositiveHeldTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingPositiveHeldTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -742,7 +742,7 @@ namespace SHADE return maxHeldTime; } - double SHInputManager::GetBindingNegativeHeldTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingNegativeHeldTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -764,7 +764,7 @@ namespace SHADE } //Fetches shortest release time - double SHInputManager::GetBindingPositiveReleasedTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingPositiveReleasedTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -785,7 +785,7 @@ namespace SHADE return minReleaseTime; } - double SHInputManager::GetBindingNegativeReleasedTime(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingNegativeReleasedTime(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; @@ -808,7 +808,7 @@ namespace SHADE //Only for mouse movement //Get largest delta - double SHInputManager::GetBindingMouseVelocity(std::string bindingName, size_t cNum) noexcept + double SHInputManager::GetBindingMouseVelocity(std::string const& bindingName, size_t cNum) noexcept { if (cNum >= XUSER_MAX_COUNT) return 0.0; diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 04e5871d..ce3e69aa 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -319,8 +319,8 @@ namespace SHADE std::set negativeControllerCodes; //Mouse movement mapped to axes? - double mouseXPositiveMultiplier; - double mouseYPositiveMultiplier; + double mouseXPositiveMultiplier = 0.0f; + double mouseYPositiveMultiplier = 0.0f; }; public: @@ -484,7 +484,7 @@ namespace SHADE } /*------------------------------------------------------------------------*/ - /* Input state accessors (KB & M) */ + /* Input state accessors (Controller) */ /*------------------------------------------------------------------------*/ //How many controller inputs of any kind are being used now @@ -622,14 +622,14 @@ namespace SHADE /*------------------------------------------------------------------------*/ //Add a new binding to the map - static inline void BindingsAdd(std::string newBindingName) noexcept + static inline void BindingsAdd(std::string const& newBindingName) noexcept { bindings.insert({ newBindingName, SHLogicalBindingData() }); } //Remove a binding from the map //Returns 1 if found and removed, 0 if not found - static inline size_t BindingsRemove(std::string targetBindingName) noexcept + static inline size_t BindingsRemove(std::string const& targetBindingName) noexcept { return bindings.erase(targetBindingName); } @@ -647,13 +647,13 @@ namespace SHADE } //Check positive keycodes to binding - static inline std::set const& BindingsGetPositiveKeyCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetPositiveKeyCodes(std::string const& bindingName) noexcept { return bindings[bindingName].positiveKeyCodes; } //Add positive SH_KEYCODE to binding - static inline void BindingsAddPositiveKeyCode(std::string targetBindingName, + static inline void BindingsAddPositiveKeyCode(std::string const& targetBindingName, SH_KEYCODE toAdd) noexcept { bindings[targetBindingName].positiveKeyCodes.insert(toAdd); @@ -661,20 +661,20 @@ namespace SHADE //Remove positive SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveKeyCode(std::string targetBindingName, + static inline size_t BindingsRemovePositiveKeyCode(std::string const& targetBindingName, SH_KEYCODE toRemove) noexcept { return bindings[targetBindingName].positiveKeyCodes.erase(toRemove); } //Check negative keycodes to binding - static inline std::set const& BindingsGetNegativeKeyCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetNegativeKeyCodes(std::string const& bindingName) noexcept { return bindings[bindingName].negativeKeyCodes; } //Add negative SH_KEYCODE to binding - static inline void BindingsAddNegativeKeyCode(std::string targetBindingName, + static inline void BindingsAddNegativeKeyCode(std::string const& targetBindingName, SH_KEYCODE toAdd) noexcept { bindings[targetBindingName].negativeKeyCodes.insert(toAdd); @@ -682,20 +682,20 @@ namespace SHADE //Remove negative SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeKeyCode(std::string targetBindingName, + static inline size_t BindingsRemoveNegativeKeyCode(std::string const& targetBindingName, SH_KEYCODE toRemove) noexcept { return bindings[targetBindingName].negativeKeyCodes.erase(toRemove); } //Check positive controllercodes to binding - static inline std::set const& BindingsGetPositiveControllerCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetPositiveControllerCodes(std::string const& bindingName) noexcept { return bindings[bindingName].positiveControllerCodes; } //Add positive SH_CONTROLLERCODE to binding - static inline void BindingsAddPositiveControllerCode(std::string targetBindingName, + static inline void BindingsAddPositiveControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toAdd) noexcept { bindings[targetBindingName].positiveControllerCodes.insert(toAdd); @@ -703,20 +703,20 @@ namespace SHADE //Remove positive SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveControllerCode(std::string targetBindingName, + static inline size_t BindingsRemovePositiveControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toRemove) noexcept { return bindings[targetBindingName].positiveControllerCodes.erase(toRemove); } //Check negative controllercodes to binding - static inline std::set const& BindingsGetNegativeControllerCodes(std::string bindingName) noexcept + static inline std::set const& BindingsGetNegativeControllerCodes(std::string const& bindingName) noexcept { return bindings[bindingName].negativeControllerCodes; } //Add negative SH_CONTROLLERCODE to binding - static inline void BindingsAddNegativeControllerCode(std::string targetBindingName, + static inline void BindingsAddNegativeControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toAdd) noexcept { bindings[targetBindingName].negativeControllerCodes.insert(toAdd); @@ -724,7 +724,7 @@ namespace SHADE //Remove negative SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeControllerCode(std::string targetBindingName, + static inline size_t BindingsRemoveNegativeControllerCode(std::string const& targetBindingName, SH_CONTROLLERCODE toRemove) noexcept { return bindings[targetBindingName].negativeControllerCodes.erase(toRemove); @@ -732,57 +732,57 @@ namespace SHADE //Mouse movement bindings - static inline double const BindingsGetMouseXPositiveMultiplier(std::string bindingName) noexcept + static inline double const BindingsGetMouseXPositiveMultiplier(std::string const& bindingName) noexcept { return bindings[bindingName].mouseXPositiveMultiplier; } - static inline void BindingsSetMouseXPositiveMultiplier(std::string bindingName, double newValue) noexcept + static inline void BindingsSetMouseXPositiveMultiplier(std::string const& bindingName, double newValue) noexcept { bindings[bindingName].mouseXPositiveMultiplier = newValue; } - static inline double const BindingsGetMouseYPositiveMultiplier(std::string bindingName) noexcept + static inline double const BindingsGetMouseYPositiveMultiplier(std::string const& bindingName) noexcept { - return bindings[bindingName].mouseXPositiveMultiplier; + return bindings[bindingName].mouseYPositiveMultiplier; } - static inline void BindingsSetMouseYPositiveMultiplier(std::string bindingName, double newValue) noexcept + static inline void BindingsSetMouseYPositiveMultiplier(std::string const& bindingName, double newValue) noexcept { - bindings[bindingName].mouseXPositiveMultiplier = newValue; + bindings[bindingName].mouseYPositiveMultiplier = newValue; } //Get the axis value of binding, between -1 and 1 - static double GetBindingAxis(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is being held or not //Does not work for mouse movement - static bool GetBindingPositiveButton(std::string bindingName, size_t controllerNumber = 0) noexcept; - static bool GetBindingNegativeButton(std::string bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingPositiveButton(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingNegativeButton(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is pressed down IN THIS FRAME ONLY //Does not work for mouse movement - static bool GetBindingPositiveButtonDown(std::string bindingName, size_t controllerNumber = 0) noexcept; - static bool GetBindingNegativeButtonDown(std::string bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingPositiveButtonDown(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingNegativeButtonDown(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is released IN THIS FRAME ONLY //Does not work for mouse movement - static bool GetBindingPositiveButtonUp(std::string bindingName, size_t controllerNumber = 0) noexcept; - static bool GetBindingNegativeButtonUp(std::string bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingPositiveButtonUp(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static bool GetBindingNegativeButtonUp(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Binding times //Does not work for mouse movement - static double GetBindingPositiveHeldTime(std::string bindingName, size_t controllerNumber = 0) noexcept; - static double GetBindingNegativeHeldTime(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingPositiveHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingNegativeHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Does not work for mouse movement - static double GetBindingPositiveReleasedTime(std::string bindingName, size_t controllerNumber = 0) noexcept; - static double GetBindingNegativeReleasedTime(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Binding mouse velocity //Only for mouse movement - static double GetBindingMouseVelocity(std::string bindingName, size_t controllerNumber = 0) noexcept; + static double GetBindingMouseVelocity(std::string const& bindingName, size_t controllerNumber = 0) noexcept; /*------------------------------------------------------------------------*/ /* Other Functions */ From 8212ed2280396a7f7383e96cd57a24a8c1f6eac4 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 20 Dec 2022 20:29:28 +0800 Subject: [PATCH 02/24] Application::Quit() no longer kills the application if in editor --- SHADE_Managed/src/Engine/Application.cxx | 9 ++++++++- SHADE_Managed/src/Engine/Application.hxx | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Engine/Application.cxx b/SHADE_Managed/src/Engine/Application.cxx index c19bafa6..06ad632f 100644 --- a/SHADE_Managed/src/Engine/Application.cxx +++ b/SHADE_Managed/src/Engine/Application.cxx @@ -44,6 +44,10 @@ namespace SHADE return false; } + bool Application::IsEditor::get() + { + return SHSystemManager::GetSystem() != nullptr; + } int Application::WindowWidth::get() { return SHGraphicsSystemInterface::GetWindowWidth(); @@ -66,6 +70,9 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ void Application::Quit() { - SHGraphicsSystemInterface::CloseWindow(); + if (!IsEditor) + { + SHGraphicsSystemInterface::CloseWindow(); + } } } diff --git a/SHADE_Managed/src/Engine/Application.hxx b/SHADE_Managed/src/Engine/Application.hxx index 8629cf75..4467ec3b 100644 --- a/SHADE_Managed/src/Engine/Application.hxx +++ b/SHADE_Managed/src/Engine/Application.hxx @@ -43,6 +43,13 @@ namespace SHADE bool get(); } /// + /// True if the engine is running in the editor. + /// + static property bool IsEditor + { + bool get(); + } + /// /// Retrieves the designated width of the current window. /// static property int WindowWidth @@ -71,6 +78,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /// /// Marks the application to stop at the end of the current frame. + /// If running in the editor, this function does nothing. /// static void Quit(); }; From 88e89a226a895c2ee0d62ac6db50e50301ac706f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 20 Dec 2022 22:35:47 +0800 Subject: [PATCH 03/24] Added the option to open the script csproj via menu bar --- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 5 ++ SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 73 ++++++++++++------- SHADE_Engine/src/Scripting/SHScriptEngine.h | 5 ++ 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index a1335e19..22d78173 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -120,6 +120,11 @@ namespace SHADE auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); scriptEngine->GenerateScriptsCsProjFile(); } + if (ImGui::Selectable("Open Visual Studio Project")) + { + auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); + scriptEngine->OpenSolution(); + } ImGui::BeginDisabled(SHSystemManager::GetSystem()->editorState != SHEditor::State::STOP); if (ImGui::Selectable("Build Scripts - Debug")) { diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 3746d1d0..76a57242 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -306,6 +306,22 @@ namespace SHADE file.close(); } + void SHScriptEngine::OpenSolution() + { + // Generate csproj file if it doesn't exist + if (!std::filesystem::exists(CSPROJ_PATH)) + { + GenerateScriptsCsProjFile(CSPROJ_PATH); + } + + // Open it + execProcessNoBlock + ( + L"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe", + L"/Edit " + SHStringUtilities::StrToWstr(CSPROJ_PATH) + ); + } + /*-----------------------------------------------------------------------------------*/ /* Event Handler Functions */ /*-----------------------------------------------------------------------------------*/ @@ -612,31 +628,7 @@ namespace SHADE DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args) { - STARTUPINFOW startInfo; - PROCESS_INFORMATION procInfo; - ZeroMemory(&startInfo, sizeof(startInfo)); - ZeroMemory(&procInfo, sizeof(procInfo)); - startInfo.cb = sizeof(startInfo); - - std::wstring argsWstr = args; - - // Start Process - const auto SUCCESS = CreateProcess - ( - path.data(), argsWstr.data(), - nullptr, nullptr, false, NULL, nullptr, nullptr, - &startInfo, &procInfo - ); - - // Error Check - if (!SUCCESS) - { - auto err = GetLastError(); - std::ostringstream oss; - oss << "[ScriptEngine] Failed to launch process. Error code: " << std::hex << err - << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; - throw std::runtime_error(oss.str()); - } + PROCESS_INFORMATION procInfo = execProcessNoBlock(path, args); // Wait for execution to end DWORD status; @@ -662,6 +654,37 @@ namespace SHADE } } + PROCESS_INFORMATION SHScriptEngine::execProcessNoBlock(const std::wstring& path, const std::wstring& args) + { + STARTUPINFOW startInfo; + PROCESS_INFORMATION procInfo; + ZeroMemory(&startInfo, sizeof(startInfo)); + ZeroMemory(&procInfo, sizeof(procInfo)); + startInfo.cb = sizeof(startInfo); + + std::wstring argsWstr = args; + + // Start Process + const auto SUCCESS = CreateProcess + ( + path.data(), argsWstr.data(), + nullptr, nullptr, false, NULL, nullptr, nullptr, + &startInfo, &procInfo + ); + + // Error Check + if (!SUCCESS) + { + auto err = GetLastError(); + std::ostringstream oss; + oss << "[ScriptEngine] Failed to launch process. Error code: " << std::hex << err + << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; + throw std::runtime_error(oss.str()); + } + + return procInfo; + } + std::wstring SHScriptEngine::generateBuildCommand(bool debug) { std::wostringstream oss; diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 1a38a678..40efa042 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -217,6 +217,10 @@ namespace SHADE /// /// File path to the generated file. void GenerateScriptsCsProjFile(const std::filesystem::path& path = CSPROJ_PATH) const; + /// + /// Opens the script solution in Visual Studio 2019. + /// + void OpenSolution(); private: /*-----------------------------------------------------------------------------*/ @@ -321,6 +325,7 @@ namespace SHADE static bool fileExists(const std::filesystem::path& filePath); static bool copyFile(const std::filesystem::path& from, const std::filesystem::path& to, const std::filesystem::copy_options options) noexcept; static DWORD execProcess(const std::wstring& path, const std::wstring& args); + static PROCESS_INFORMATION execProcessNoBlock(const std::wstring& path, const std::wstring& args); static std::wstring generateBuildCommand(bool debug); }; } From 360b362b7b4500052790f2d61ac8b367812ad8c2 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 21 Dec 2022 16:47:10 +0800 Subject: [PATCH 04/24] Moved command and process execution helpers to SHExecUtilities --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 68 +----------- SHADE_Engine/src/Scripting/SHScriptEngine.h | 4 +- .../src/Tools/Utilities/SHExecUtilities.cpp | 103 ++++++++++++++++++ .../src/Tools/Utilities/SHExecUtilities.h | 84 ++++++++++++++ 4 files changed, 191 insertions(+), 68 deletions(-) create mode 100644 SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp create mode 100644 SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 76a57242..b4f893d7 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -30,6 +30,7 @@ of DigiPen Institute of Technology is prohibited. #include "Scene/SHSceneEvents.h" #include "Assets/SHAssetMacros.h" +#include "Tools/Utilities/SHExecUtilities.h" namespace SHADE { @@ -189,11 +190,7 @@ namespace SHADE oss << "[ScriptEngine] Building " << (debug ? " debug " : "") << "Managed Script Assembly (" << MANAGED_SCRIPT_LIB_NAME << ")!"; SHLOG_INFO(oss.str()); oss.str(""); - const bool BUILD_SUCCESS = execProcess - ( - L"C:\\Windows\\system32\\cmd.exe", - L"/K \"" + generateBuildCommand(debug) + L" & exit\"" - ) == 0; + const bool BUILD_SUCCESS = SHExecUtilties::ExecBlockingCommand(generateBuildCommand(debug)) == 0; if (BUILD_SUCCESS) { // Copy to built dll to the working directory and replace @@ -315,7 +312,7 @@ namespace SHADE } // Open it - execProcessNoBlock + SHExecUtilties::ExecProcess ( L"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe", L"/Edit " + SHStringUtilities::StrToWstr(CSPROJ_PATH) @@ -626,65 +623,6 @@ namespace SHADE } } - DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args) - { - PROCESS_INFORMATION procInfo = execProcessNoBlock(path, args); - - // Wait for execution to end - DWORD status; - while (true) - { - const auto EXEC_SUCCESS = GetExitCodeProcess(procInfo.hProcess, &status); - if (!EXEC_SUCCESS) - { - auto err = GetLastError(); - std::ostringstream oss; - oss << "[ScriptEngine] Failed to query process. Error code: " << std::hex << err - << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; - throw std::runtime_error(oss.str()); - } - - // Break only if process ends - if (status != STILL_ACTIVE) - { - CloseHandle(procInfo.hProcess); - CloseHandle(procInfo.hThread); - return status; - } - } - } - - PROCESS_INFORMATION SHScriptEngine::execProcessNoBlock(const std::wstring& path, const std::wstring& args) - { - STARTUPINFOW startInfo; - PROCESS_INFORMATION procInfo; - ZeroMemory(&startInfo, sizeof(startInfo)); - ZeroMemory(&procInfo, sizeof(procInfo)); - startInfo.cb = sizeof(startInfo); - - std::wstring argsWstr = args; - - // Start Process - const auto SUCCESS = CreateProcess - ( - path.data(), argsWstr.data(), - nullptr, nullptr, false, NULL, nullptr, nullptr, - &startInfo, &procInfo - ); - - // Error Check - if (!SUCCESS) - { - auto err = GetLastError(); - std::ostringstream oss; - oss << "[ScriptEngine] Failed to launch process. Error code: " << std::hex << err - << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; - throw std::runtime_error(oss.str()); - } - - return procInfo; - } - std::wstring SHScriptEngine::generateBuildCommand(bool debug) { std::wostringstream oss; diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 40efa042..d26b360e 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -1,5 +1,5 @@ /************************************************************************************//*! -\file ScriptEngine.h +\file SHScriptEngine.h \author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu \date Sep 17, 2021 @@ -324,8 +324,6 @@ namespace SHADE /// True if the file exists static bool fileExists(const std::filesystem::path& filePath); static bool copyFile(const std::filesystem::path& from, const std::filesystem::path& to, const std::filesystem::copy_options options) noexcept; - static DWORD execProcess(const std::wstring& path, const std::wstring& args); - static PROCESS_INFORMATION execProcessNoBlock(const std::wstring& path, const std::wstring& args); static std::wstring generateBuildCommand(bool debug); }; } diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp new file mode 100644 index 00000000..c1bae764 --- /dev/null +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp @@ -0,0 +1,103 @@ +/************************************************************************************//*! +\file SHExecUtilities.cpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Dec 21, 2022 +\brief Contains the implementation for SHExecUtilities static class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include +// Primary Header +#include "SHExecUtilities.h" +// Project Includes +#include "SHStringUtilities.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Process Execution Functions */ + /*-----------------------------------------------------------------------------------*/ + PROCESS_INFORMATION SHExecUtilties::ExecProcess(const std::wstring& path, const std::wstring& args) + { + STARTUPINFOW startInfo; + PROCESS_INFORMATION procInfo; + ZeroMemory(&startInfo, sizeof(startInfo)); + ZeroMemory(&procInfo, sizeof(procInfo)); + startInfo.cb = sizeof(startInfo); + + std::wstring argsWstr = args; + + // Start Process + const auto SUCCESS = CreateProcess + ( + path.data(), argsWstr.data(), + nullptr, nullptr, false, NULL, nullptr, nullptr, + &startInfo, &procInfo + ); + + // Error Check + if (!SUCCESS) + { + auto err = GetLastError(); + std::ostringstream oss; + oss << "[SHExecUtilties] Failed to launch process. Error code: " << std::hex << err + << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; + throw std::runtime_error(oss.str()); + } + + return procInfo; + } + + DWORD SHExecUtilties::ExecBlockingProcess(const std::wstring& path, const std::wstring& args) + { + PROCESS_INFORMATION procInfo = ExecProcess(path, args); + + // Wait for execution to end + DWORD status; + while (true) + { + const auto EXEC_SUCCESS = GetExitCodeProcess(procInfo.hProcess, &status); + if (!EXEC_SUCCESS) + { + auto err = GetLastError(); + std::ostringstream oss; + oss << "[SHExecUtilties] Failed to query process. Error code: " << std::hex << err + << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; + throw std::runtime_error(oss.str()); + } + + // Break only if process ends + if (status != STILL_ACTIVE) + { + CloseHandle(procInfo.hProcess); + CloseHandle(procInfo.hThread); + return status; + } + } + } + + /*-----------------------------------------------------------------------------------*/ + /* Command Execution Functions */ + /*-----------------------------------------------------------------------------------*/ + PROCESS_INFORMATION SHExecUtilties::ExecCommand(const std::wstring& command) + { + return ExecProcess + ( + L"C:\\Windows\\system32\\cmd.exe", + L"/K \"" + command + L" & exit\"" + ); + } + + DWORD SHExecUtilties::ExecBlockingCommand(const std::wstring& command) + { + return ExecBlockingProcess + ( + L"C:\\Windows\\system32\\cmd.exe", + L"/K \"" + command + L" & exit\"" + ); + } +} diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h new file mode 100644 index 00000000..838cee41 --- /dev/null +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h @@ -0,0 +1,84 @@ +/************************************************************************************//*! +\file SHExecUtilties.h +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Dec 21, 2022 +\brief Contains the interface for SHExecUtilities class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ + +// STL Includes +#include +// External Dependencies +#include + +namespace SHADE +{ + /// + /// Static class containing functions for executing external processes or commands. + /// + class SH_API SHExecUtilties final + { + public: + /*---------------------------------------------------------------------------------*/ + /* Process Execution Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Executes a process at the specified path with the specified arguments. This call + /// does not wait for the process to finish executing. + /// + /// Path to the processs to start. + /// Arguments to pass to the process. + /// Information about the started process. + /// + /// Thrown if failed to start the process. + /// + static PROCESS_INFORMATION ExecProcess(const std::wstring& path, const std::wstring& args); + /// + /// Executes a process at the specified path with the specified arguments and waits + /// for that process to finish executing. + /// + /// Path to the processs to start. + /// Arguments to pass to the process. + /// Return value of the process. + /// + /// Thrown if failed to start the process. + /// + static DWORD ExecBlockingProcess(const std::wstring& path, const std::wstring& args); + + /*---------------------------------------------------------------------------------*/ + /* Command Execution Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Executes a specified command in cmd. + /// This call does not wait for the command to finish executing. + /// + /// Command to execute. + /// + /// Information about the started cmd process that executes the command. + /// + /// + /// Thrown if failed to start the process. + /// + static PROCESS_INFORMATION ExecCommand(const std::wstring& command); + /// + /// Executes a specified command in cmd and waits for that process to finish + /// executing. + /// + /// Command to execute. + /// Return value of the process. + /// + /// Thrown if failed to start the process. + /// + static DWORD ExecBlockingCommand(const std::wstring& command); + + private: + /*-------------------------------------------------------------------------------*/ + /* Constructors/Destructors */ + /*-------------------------------------------------------------------------------*/ + SHExecUtilties() = delete; + }; +} From 861e47812f40b64ad711e02988b04b511520e5af Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 22 Dec 2022 15:06:52 +0800 Subject: [PATCH 05/24] Fixed bug where StrToWstr and WstrToStr may contain invalid characters from a previous call --- .../src/Tools/Utilities/SHStringUtilities.cpp | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/SHADE_Engine/src/Tools/Utilities/SHStringUtilities.cpp b/SHADE_Engine/src/Tools/Utilities/SHStringUtilities.cpp index b1e4aa92..b9698071 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHStringUtilities.cpp +++ b/SHADE_Engine/src/Tools/Utilities/SHStringUtilities.cpp @@ -26,27 +26,29 @@ namespace SHADE std::vector SHStringUtilities::Split(const std::wstring& str, const wchar_t& delim) { return Split(str, delim); - } - std::string SHStringUtilities::WstrToStr(const std::wstring& wstr) - { - static std::vector buffer; - const int STR_SIZE = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast(wstr.size()), nullptr, 0, nullptr, nullptr) + 1 /* Null Terminator */; - buffer.resize(STR_SIZE); - WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast(wstr.size()), buffer.data(), MAX_PATH, nullptr, nullptr); - return std::string(buffer.data()); - } - std::wstring SHStringUtilities::StrToWstr(const std::string& str) - { - static std::vector buffer; - const int WSTR_SIZE = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), nullptr, 0) + 1 /* Null Terminator */; - buffer.resize(WSTR_SIZE); - MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), buffer.data(), WSTR_SIZE); - return std::wstring(buffer.data()); - } + } + std::string SHStringUtilities::WstrToStr(const std::wstring& wstr) + { + static std::vector buffer; + buffer.clear(); + const int STR_SIZE = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast(wstr.size()), nullptr, 0, nullptr, nullptr) + 1 /* Null Terminator */; + buffer.resize(STR_SIZE, '\0'); + WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast(wstr.size()), buffer.data(), MAX_PATH, nullptr, nullptr); + return std::string(buffer.data()); + } + std::wstring SHStringUtilities::StrToWstr(const std::string& str) + { + static std::vector buffer; + buffer.clear(); + const int WSTR_SIZE = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), nullptr, 0) + 1 /* Null Terminator */; + buffer.resize(WSTR_SIZE, '\0'); + MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), buffer.data(), WSTR_SIZE); + return std::wstring(buffer.data()); + } - std::string SHStringUtilities::GetWin32ErrorMessage(unsigned long errorCode) - { - return std::system_category().message(errorCode); - } + std::string SHStringUtilities::GetWin32ErrorMessage(unsigned long errorCode) + { + return std::system_category().message(errorCode); + } } \ No newline at end of file From 605d408a3aafb975a0e13c2dcfcf7e6fffdf8574 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Fri, 23 Dec 2022 15:24:12 +0800 Subject: [PATCH 06/24] Binding types, scroll wheel support, bind clears --- SHADE_Engine/src/Input/SHInputManager.cpp | 46 ++++---- SHADE_Engine/src/Input/SHInputManager.h | 126 +++++++++++++++++----- 2 files changed, 126 insertions(+), 46 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index f6b58a94..01bd4c13 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -577,18 +577,42 @@ namespace SHADE //Only get of largest magnitude double SHInputManager::GetBindingAxis(std::string const& bindingName, size_t cNum) noexcept { + if (cNum >= XUSER_MAX_COUNT) return 0.0f; + + //Over mouse movement, if used for this axis + if (bindings[bindingName].bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_X) + { + double velX = 0.0f; + GetMouseVelocity(&velX, nullptr); + return velX; + } + + if (bindings[bindingName].bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_Y) + { + double velY = 0.0f; + GetMouseVelocity(nullptr, &velY); + return velY; + } + + //Over mouse scroll, if used for this axis + if (bindings[bindingName].bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_SCROLL) + { + return mouseWheelVerticalDelta; + } + + //The largest magnitude recorded so far + double largestMagnitude = 0.0; + //Over keycodes, prioritise positive for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes) { - if (GetKey(k)) return 1.0; + if (GetKey(k)) if (std::abs(1.0f) > std::abs(largestMagnitude)) largestMagnitude = 1.0f; } for (SH_KEYCODE k : bindings[bindingName].negativeKeyCodes) { - if (GetKey(k)) return -1.0; + if (GetKey(k)) if (std::abs(-1.0f) > std::abs(largestMagnitude)) largestMagnitude = -1.0f; } - double largestMagnitude = 0.0; - //Over controllerCodes for (SH_CONTROLLERCODE c : bindings[bindingName].positiveControllerCodes) { @@ -806,18 +830,4 @@ namespace SHADE return minReleaseTime; } - //Only for mouse movement - //Get largest delta - double SHInputManager::GetBindingMouseVelocity(std::string const& bindingName, size_t cNum) noexcept - { - if (cNum >= XUSER_MAX_COUNT) return 0.0; - - //Mouse velocity - double velX = 0.0; - double velY = 0.0; - GetMouseVelocity(&velX, &velY); - - return bindings[bindingName].mouseXPositiveMultiplier * velX + bindings[bindingName].mouseYPositiveMultiplier * velY; - } - } //namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index ce3e69aa..3c503336 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -306,6 +306,20 @@ namespace SHADE /*------------------------------------------------------------------------*/ struct SH_API SHLogicalBindingData { + //BINDING TYPES/////////////////////////////////////////////////////////// + enum class SH_BINDINGTYPE + { + KB_MB_CONTROLLER, + MOUSE_X, + MOUSE_Y, + MOUSE_SCROLL + }; + + //BINDINGS//////////////////////////////////////////////////////////////// + + //The type of the binding + SH_BINDINGTYPE bindingType = SH_BINDINGTYPE::KB_MB_CONTROLLER; + //Key codes mapped to positive std::set positiveKeyCodes; @@ -318,9 +332,32 @@ namespace SHADE //Controller Codes mapped to negative std::set negativeControllerCodes; - //Mouse movement mapped to axes? - double mouseXPositiveMultiplier = 0.0f; - double mouseYPositiveMultiplier = 0.0f; + //VALUES////////////////////////////////////////////////////////////////// + + //The current value of the axis binding + double value = 0.0f; + + //Whether the input is inverted, + //If so, positive bindings will make the value negative, + // negative bindings will make the value positive, + // moving the mouse up will make the value negative, + // scrolling the mousewheel up will make the value negative, + bool inverted = false; + + //When no input is present, how fast does the value fall back to neutral? + double gravity = 1.0f; + + //How far the user needs to move an analog stick before application + //registers the movement + double dead = 0.1f; + + //Speed in units per second that the axis will move toward target value + //For digital inputs only + double sensitivity = 1.0f; + + //If enabled, axis value will reset to zero when pressing a button + //that corresponds in the opposite direction + bool snap = false; }; public: @@ -350,6 +387,12 @@ namespace SHADE mouseWheelVerticalDeltaPoll += GET_WHEEL_DELTA_WPARAM(wParam); } + //Get if controller or KB/M is presently being used + static inline bool const GetControllerInUse() noexcept + { + return controllerInUse; + } + //For testing purposes //static void PrintCurrentState() noexcept; @@ -621,13 +664,19 @@ namespace SHADE /* Binding Functions */ /*------------------------------------------------------------------------*/ + //Get a read-only map of the bindings + static inline std::map const& getBindings() noexcept + { + return bindings; + } + //Add a new binding to the map static inline void BindingsAdd(std::string const& newBindingName) noexcept { bindings.insert({ newBindingName, SHLogicalBindingData() }); } - //Remove a binding from the map + //Remove a binding and all its associated inputs from the list //Returns 1 if found and removed, 0 if not found static inline size_t BindingsRemove(std::string const& targetBindingName) noexcept { @@ -646,6 +695,20 @@ namespace SHADE return bindings.size(); } + //BINDING TYPE////////////////////////////////////////////////////////////// + + static inline void BindingsSetType(std::string const& targetBindingName, SHLogicalBindingData::SH_BINDINGTYPE const newType) + { + bindings[targetBindingName].bindingType = newType; + } + + static inline SHLogicalBindingData::SH_BINDINGTYPE const BindingsGetType(std::string const& targetBindingName) + { + return bindings[targetBindingName].bindingType; + } + + //POSITIVE KEYCODES///////////////////////////////////////////////////////// + //Check positive keycodes to binding static inline std::set const& BindingsGetPositiveKeyCodes(std::string const& bindingName) noexcept { @@ -667,6 +730,14 @@ namespace SHADE return bindings[targetBindingName].positiveKeyCodes.erase(toRemove); } + //Clear all positive SH_KEYCODEs from binding + static inline void BindingsClearPositiveKeyCodes(std::string const& targetBindingName) noexcept + { + bindings[targetBindingName].positiveKeyCodes.clear(); + } + + //NEGATIVE KEYCODES///////////////////////////////////////////////////////// + //Check negative keycodes to binding static inline std::set const& BindingsGetNegativeKeyCodes(std::string const& bindingName) noexcept { @@ -688,6 +759,14 @@ namespace SHADE return bindings[targetBindingName].negativeKeyCodes.erase(toRemove); } + //Clear all negative SH_KEYCODEs from binding + static inline void BindingsClearNegativeKeyCodes(std::string const& targetBindingName) noexcept + { + bindings[targetBindingName].negativeKeyCodes.clear(); + } + + //POSITIVE CONTROLLERCODES////////////////////////////////////////////////// + //Check positive controllercodes to binding static inline std::set const& BindingsGetPositiveControllerCodes(std::string const& bindingName) noexcept { @@ -709,6 +788,14 @@ namespace SHADE return bindings[targetBindingName].positiveControllerCodes.erase(toRemove); } + //Clear all positive SH_CONTROLLERCODEs from binding + static inline void BindingsClearPositiveControllerCodes(std::string const& targetBindingName) noexcept + { + bindings[targetBindingName].positiveControllerCodes.clear(); + } + + //NEGATIVE CONTROLLERCODES////////////////////////////////////////////////// + //Check negative controllercodes to binding static inline std::set const& BindingsGetNegativeControllerCodes(std::string const& bindingName) noexcept { @@ -730,29 +817,16 @@ namespace SHADE return bindings[targetBindingName].negativeControllerCodes.erase(toRemove); } - //Mouse movement bindings - - static inline double const BindingsGetMouseXPositiveMultiplier(std::string const& bindingName) noexcept + //Clear all negative SH_CONTROLLERCODEs from binding + static inline void BindingsClearNegativeControllerCodes(std::string const& targetBindingName) noexcept { - return bindings[bindingName].mouseXPositiveMultiplier; + bindings[targetBindingName].negativeControllerCodes.clear(); } - static inline void BindingsSetMouseXPositiveMultiplier(std::string const& bindingName, double newValue) noexcept - { - bindings[bindingName].mouseXPositiveMultiplier = newValue; - } - - static inline double const BindingsGetMouseYPositiveMultiplier(std::string const& bindingName) noexcept - { - return bindings[bindingName].mouseYPositiveMultiplier; - } - - static inline void BindingsSetMouseYPositiveMultiplier(std::string const& bindingName, double newValue) noexcept - { - bindings[bindingName].mouseYPositiveMultiplier = newValue; - } - - //Get the axis value of binding, between -1 and 1 + //Get the axis value of binding, between -1 and 1 for non-mouse + //For mouse, it won't be between -1 and 1. It will also be multiplied by sensitivity + //To avoid interference between mouse movement/wheel and keyboard/mouse/controller input, + //Set mouseXBound, mouseYBound and mouseScrollBound to false static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is being held or not @@ -780,10 +854,6 @@ namespace SHADE static double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; static double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; - //Binding mouse velocity - //Only for mouse movement - static double GetBindingMouseVelocity(std::string const& bindingName, size_t controllerNumber = 0) noexcept; - /*------------------------------------------------------------------------*/ /* Other Functions */ /*------------------------------------------------------------------------*/ From ee4ec83f7a33a9e235043f613c72240e909b21e4 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Sun, 25 Dec 2022 14:13:21 +0800 Subject: [PATCH 07/24] Progress on Input Manager Fixes --- SHADE_Engine/src/Input/SHInputManager.cpp | 188 +++++++++++++++------- SHADE_Engine/src/Input/SHInputManager.h | 129 ++++++++++----- 2 files changed, 225 insertions(+), 92 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index 01bd4c13..a1ebe1a6 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -159,7 +159,7 @@ namespace SHADE } } - //Mouse Positioning///////////////////////////////////// + //Mouse Positioning///////////////////////////////////////////////////////// //https://stackoverflow.com/a/6423739 //Set last positioning @@ -181,7 +181,7 @@ namespace SHADE mouseWheelVerticalDelta = mouseWheelVerticalDeltaPoll; mouseWheelVerticalDeltaPoll = 0; - //Controllers////////////////////////////////////////////////////////////// + //Controllers/////////////////////////////////////////////////////////////// controllersConnectedCount = 0; @@ -447,6 +447,137 @@ namespace SHADE } } } + + //Bindings////////////////////////////////////////////////////////////////// + for (std::pair binding : bindings) + { + SHLogicalBindingData& data = binding.second; + + if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_X) + { + double velX = 0.0; + GetMouseVelocity(&velX, nullptr); + data.value = velX * data.sensitivity * (data.inverted ? -1.0 : 1.0); + } + else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_Y) + { + double velY = 0.0; + GetMouseVelocity(nullptr, &velY); + data.value = velY * data.sensitivity * (data.inverted ? -1.0 : 1.0); + } + else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_SCROLL) + { + data.value = mouseWheelVerticalDelta * data.sensitivity * (data.inverted ? -1.0 : 1.0); + } + else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::KB_MB_CONTROLLER) + { + //Prioritise the largest magnitude + double largestMagnitude = 0.0; + + //If digital input was in, use sensitivity + bool digitalInput = false; + + //If data was read + bool positiveInputRead = false; + bool negativeInputRead = false; + + //Over keycodes + for (SH_KEYCODE k : data.positiveKeyCodes) + { + if (GetKey(k)) + { + if (std::abs(1.0) > std::abs(largestMagnitude)) largestMagnitude = 1.0; + digitalInput = true; + positiveInputRead = true; + } + } + for (SH_KEYCODE k : data.negativeKeyCodes) + { + if (GetKey(k)) + { + if (std::abs(-1.0) > std::abs(largestMagnitude)) largestMagnitude = -1.0; + digitalInput = true; + negativeInputRead = true; + } + } + + //Over controllerCodes + for (SH_CONTROLLERCODE c : data.positiveControllerCodes) + { + double newValue = 0.0; + if (GetControllerInput(c, &newValue)) + { + positiveInputRead = true; + if (static_cast(c) < NUM_CONTROLLER_BUTTON) + { + digitalInput = true; + } + if (std::abs(newValue) > std::abs(largestMagnitude)) + largestMagnitude = newValue * data.sensitivity * (data.inverted ? -1.0 : 1.0); + } + } + + for (SH_CONTROLLERCODE c : data.negativeControllerCodes) + { + double newValue = 0.0; + if (GetControllerInput(c, &newValue)) + { + negativeInputRead = true; + if (static_cast(c) < NUM_CONTROLLER_BUTTON) + { + digitalInput = true; + } + if (std::abs(newValue) > std::abs(largestMagnitude)) + largestMagnitude = -newValue * data.sensitivity * (data.inverted ? -1.0 : 1.0); + } + } + + //If both positive and negative inputs read, do not modify value + if (positiveInputRead && negativeInputRead) + { + data.value = data.value; + } + else + { + //If no data received, use gravity + if (!positiveInputRead && !negativeInputRead) + { + if (data.value > 0.0) + { + data.value -= data.gravity * dt; + if (data.value < 0.0) data.value = 0.0; + } + if (data.value < 0.0) + { + data.value += data.gravity * dt; + if (data.value > 0.0) data.value = 0.0; + } + } + else //Either positive OR negative input was read + { + //If digital input was in, use sensitivity + if (digitalInput) + { + data.value += data.sensitivity * largestMagnitude * dt; + if (data.value > 1.0) data.value = 1.0; + else if (data.value < -1.0) data.value = -1.0; + } + else + { + data.value = largestMagnitude; + } + + if (data.snap) //Snapping + { + if (data.value > 0.0 && negativeInputRead) + data.value = 0.0; + if (data.value < 0.0 && positiveInputRead) + data.value = 0.0; + } + } + } + } + } } bool SHInputManager::AnyKeyDown(SH_KEYCODE* firstDetected) noexcept @@ -574,60 +705,9 @@ namespace SHADE return false; } - //Only get of largest magnitude double SHInputManager::GetBindingAxis(std::string const& bindingName, size_t cNum) noexcept { - if (cNum >= XUSER_MAX_COUNT) return 0.0f; - - //Over mouse movement, if used for this axis - if (bindings[bindingName].bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_X) - { - double velX = 0.0f; - GetMouseVelocity(&velX, nullptr); - return velX; - } - - if (bindings[bindingName].bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_Y) - { - double velY = 0.0f; - GetMouseVelocity(nullptr, &velY); - return velY; - } - - //Over mouse scroll, if used for this axis - if (bindings[bindingName].bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_SCROLL) - { - return mouseWheelVerticalDelta; - } - - //The largest magnitude recorded so far - double largestMagnitude = 0.0; - - //Over keycodes, prioritise positive - for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes) - { - if (GetKey(k)) if (std::abs(1.0f) > std::abs(largestMagnitude)) largestMagnitude = 1.0f; - } - for (SH_KEYCODE k : bindings[bindingName].negativeKeyCodes) - { - if (GetKey(k)) if (std::abs(-1.0f) > std::abs(largestMagnitude)) largestMagnitude = -1.0f; - } - - //Over controllerCodes - for (SH_CONTROLLERCODE c : bindings[bindingName].positiveControllerCodes) - { - double newValue = 0.0; - if (GetControllerInput(c, &newValue, nullptr, nullptr, cNum)) - if (std::abs(newValue) > std::abs(largestMagnitude)) largestMagnitude = newValue; - } - for (SH_CONTROLLERCODE c : bindings[bindingName].negativeControllerCodes) - { - double newValue = 0.0; - if (GetControllerInput(c, &newValue, nullptr, nullptr, cNum)) - if (std::abs(newValue) > std::abs(largestMagnitude)) largestMagnitude = -newValue; - } - - return largestMagnitude; + return bindings[bindingName].value; } bool SHInputManager::GetBindingPositiveButton(std::string const& bindingName, size_t cNum) noexcept diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 3c503336..df996647 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -335,7 +335,7 @@ namespace SHADE //VALUES////////////////////////////////////////////////////////////////// //The current value of the axis binding - double value = 0.0f; + double value = 0.0; //Whether the input is inverted, //If so, positive bindings will make the value negative, @@ -345,15 +345,16 @@ namespace SHADE bool inverted = false; //When no input is present, how fast does the value fall back to neutral? - double gravity = 1.0f; + //Best to be non-negative + double gravity = 1.0; //How far the user needs to move an analog stick before application //registers the movement - double dead = 0.1f; + double dead = 0.1; - //Speed in units per second that the axis will move toward target value - //For digital inputs only - double sensitivity = 1.0f; + //Speed in units per second that the axis will move toward target value for digital + //For mouse movement / scrolling, serves as multiplier + double sensitivity = 1.0; //If enabled, axis value will reset to zero when pressing a button //that corresponds in the opposite direction @@ -388,7 +389,7 @@ namespace SHADE } //Get if controller or KB/M is presently being used - static inline bool const GetControllerInUse() noexcept + static inline bool GetControllerInUse() noexcept { return controllerInUse; } @@ -678,9 +679,9 @@ namespace SHADE //Remove a binding and all its associated inputs from the list //Returns 1 if found and removed, 0 if not found - static inline size_t BindingsRemove(std::string const& targetBindingName) noexcept + static inline size_t BindingsRemove(std::string const& bindingName) noexcept { - return bindings.erase(targetBindingName); + return bindings.erase(bindingName); } //Clears all bindings from the list @@ -695,16 +696,68 @@ namespace SHADE return bindings.size(); } - //BINDING TYPE////////////////////////////////////////////////////////////// + //BINDING VALUES//////////////////////////////////////////////////////////// - static inline void BindingsSetType(std::string const& targetBindingName, SHLogicalBindingData::SH_BINDINGTYPE const newType) + static inline bool BindingsGetInverted(std::string const& bindingName) { - bindings[targetBindingName].bindingType = newType; + return bindings[bindingName].inverted; } - static inline SHLogicalBindingData::SH_BINDINGTYPE const BindingsGetType(std::string const& targetBindingName) + static inline void BindingsSetInverted(std::string const& bindingName, bool const newValue) { - return bindings[targetBindingName].bindingType; + bindings[bindingName].inverted = newValue; + } + + static inline double BindingsGetGravity(std::string const& bindingName) + { + return bindings[bindingName].gravity; + } + + static inline void BindingsSetGravity(std::string const& bindingName, double const newValue) + { + bindings[bindingName].gravity = newValue; + } + + static inline double BindingsGetDead(std::string const& bindingName) + { + return bindings[bindingName].dead; + } + + static inline void BindingsSetDead(std::string const& bindingName, double const newValue) + { + bindings[bindingName].dead = newValue; + } + + static inline double BindingsGetSensitivity(std::string const& bindingName) + { + return bindings[bindingName].sensitivity; + } + + static inline void BindingsSetSensitivity(std::string const& bindingName, double const newValue) + { + bindings[bindingName].sensitivity = newValue; + } + + static inline bool BindingsGetSnap(std::string const& bindingName) + { + return bindings[bindingName].snap; + } + + static inline void BindingsSetSnap(std::string const& bindingName, bool const newValue) + { + bindings[bindingName].snap = newValue; + } + + //BINDING TYPE////////////////////////////////////////////////////////////// + + static inline SHLogicalBindingData::SH_BINDINGTYPE BindingsGetType(std::string const& bindingName) + { + return bindings[bindingName].bindingType; + } + + static inline void BindingsSetType(std::string const& bindingName, SHLogicalBindingData::SH_BINDINGTYPE const newType) + { + bindings[bindingName].bindingType = newType; } //POSITIVE KEYCODES///////////////////////////////////////////////////////// @@ -716,24 +769,24 @@ namespace SHADE } //Add positive SH_KEYCODE to binding - static inline void BindingsAddPositiveKeyCode(std::string const& targetBindingName, + static inline void BindingsAddPositiveKeyCode(std::string const& bindingName, SH_KEYCODE toAdd) noexcept { - bindings[targetBindingName].positiveKeyCodes.insert(toAdd); + bindings[bindingName].positiveKeyCodes.insert(toAdd); } //Remove positive SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveKeyCode(std::string const& targetBindingName, + static inline size_t BindingsRemovePositiveKeyCode(std::string const& bindingName, SH_KEYCODE toRemove) noexcept { - return bindings[targetBindingName].positiveKeyCodes.erase(toRemove); + return bindings[bindingName].positiveKeyCodes.erase(toRemove); } //Clear all positive SH_KEYCODEs from binding - static inline void BindingsClearPositiveKeyCodes(std::string const& targetBindingName) noexcept + static inline void BindingsClearPositiveKeyCodes(std::string const& bindingName) noexcept { - bindings[targetBindingName].positiveKeyCodes.clear(); + bindings[bindingName].positiveKeyCodes.clear(); } //NEGATIVE KEYCODES///////////////////////////////////////////////////////// @@ -745,24 +798,24 @@ namespace SHADE } //Add negative SH_KEYCODE to binding - static inline void BindingsAddNegativeKeyCode(std::string const& targetBindingName, + static inline void BindingsAddNegativeKeyCode(std::string const& bindingName, SH_KEYCODE toAdd) noexcept { - bindings[targetBindingName].negativeKeyCodes.insert(toAdd); + bindings[bindingName].negativeKeyCodes.insert(toAdd); } //Remove negative SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeKeyCode(std::string const& targetBindingName, + static inline size_t BindingsRemoveNegativeKeyCode(std::string const& bindingName, SH_KEYCODE toRemove) noexcept { - return bindings[targetBindingName].negativeKeyCodes.erase(toRemove); + return bindings[bindingName].negativeKeyCodes.erase(toRemove); } //Clear all negative SH_KEYCODEs from binding - static inline void BindingsClearNegativeKeyCodes(std::string const& targetBindingName) noexcept + static inline void BindingsClearNegativeKeyCodes(std::string const& bindingName) noexcept { - bindings[targetBindingName].negativeKeyCodes.clear(); + bindings[bindingName].negativeKeyCodes.clear(); } //POSITIVE CONTROLLERCODES////////////////////////////////////////////////// @@ -774,24 +827,24 @@ namespace SHADE } //Add positive SH_CONTROLLERCODE to binding - static inline void BindingsAddPositiveControllerCode(std::string const& targetBindingName, + static inline void BindingsAddPositiveControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toAdd) noexcept { - bindings[targetBindingName].positiveControllerCodes.insert(toAdd); + bindings[bindingName].positiveControllerCodes.insert(toAdd); } //Remove positive SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveControllerCode(std::string const& targetBindingName, + static inline size_t BindingsRemovePositiveControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toRemove) noexcept { - return bindings[targetBindingName].positiveControllerCodes.erase(toRemove); + return bindings[bindingName].positiveControllerCodes.erase(toRemove); } //Clear all positive SH_CONTROLLERCODEs from binding - static inline void BindingsClearPositiveControllerCodes(std::string const& targetBindingName) noexcept + static inline void BindingsClearPositiveControllerCodes(std::string const& bindingName) noexcept { - bindings[targetBindingName].positiveControllerCodes.clear(); + bindings[bindingName].positiveControllerCodes.clear(); } //NEGATIVE CONTROLLERCODES////////////////////////////////////////////////// @@ -803,24 +856,24 @@ namespace SHADE } //Add negative SH_CONTROLLERCODE to binding - static inline void BindingsAddNegativeControllerCode(std::string const& targetBindingName, + static inline void BindingsAddNegativeControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toAdd) noexcept { - bindings[targetBindingName].negativeControllerCodes.insert(toAdd); + bindings[bindingName].negativeControllerCodes.insert(toAdd); } //Remove negative SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeControllerCode(std::string const& targetBindingName, + static inline size_t BindingsRemoveNegativeControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toRemove) noexcept { - return bindings[targetBindingName].negativeControllerCodes.erase(toRemove); + return bindings[bindingName].negativeControllerCodes.erase(toRemove); } //Clear all negative SH_CONTROLLERCODEs from binding - static inline void BindingsClearNegativeControllerCodes(std::string const& targetBindingName) noexcept + static inline void BindingsClearNegativeControllerCodes(std::string const& bindingName) noexcept { - bindings[targetBindingName].negativeControllerCodes.clear(); + bindings[bindingName].negativeControllerCodes.clear(); } //Get the axis value of binding, between -1 and 1 for non-mouse From b035582b304fe749349d1221e3692f9c1973cf9c Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 25 Dec 2022 14:32:50 +0800 Subject: [PATCH 08/24] Renamed SHGraphicsGlobalData to SHPredefinedData - SHPredefinedData now contains the font data descriptor set layout as well - Added a function for SHPredefinedData to retrieve descriptor sets based on a bitfield - Modified descriptor sets to not be tied to a set index anymore - Descriptor set layout doesn't have a set anymore - Removed desc set index constants from SHGraphicsConstants since they aren't really needed anymore --- .../Descriptors/SHVkDescriptorSetGroup.cpp | 17 +- .../Descriptors/SHVkDescriptorSetGroup.h | 9 +- .../Descriptors/SHVkDescriptorSetLayout.cpp | 256 +++++++++--------- .../Descriptors/SHVkDescriptorSetLayout.h | 194 +++++++------ .../Graphics/Devices/SHVkLogicalDevice.cpp | 4 +- .../src/Graphics/Devices/SHVkLogicalDevice.h | 2 +- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 4 +- ...icsGlobalData.cpp => SHPredefinedData.cpp} | 77 ++++-- ...raphicsGlobalData.h => SHPredefinedData.h} | 14 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 133 ++++----- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 33 ++- .../MiddleEnd/Interface/SHRenderer.cpp | 7 +- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 2 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 4 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 6 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.h | 2 +- .../MiddleEnd/TextRendering/SHFont.cpp | 2 +- .../SHTextRenderingSubSystem.cpp | 31 +-- .../TextRendering/SHTextRenderingSubSystem.h | 4 +- .../MiddleEnd/Textures/SHTextureLibrary.cpp | 4 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 2 +- .../src/Graphics/RenderGraph/SHRenderGraph.h | 2 +- .../Graphics/RenderGraph/SHRenderGraphNode.h | 2 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 4 +- .../RenderGraph/SHRenderGraphStorage.h | 2 +- .../SHRenderToSwapchainImageSystem.cpp | 4 +- .../src/Tools/Utilities/SHUtilities.h | 67 +++++ 27 files changed, 483 insertions(+), 405 deletions(-) rename SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/{SHGraphicsGlobalData.cpp => SHPredefinedData.cpp} (63%) rename SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/{SHGraphicsGlobalData.h => SHPredefinedData.h} (76%) diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp index adb51586..e77234ca 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp @@ -53,7 +53,6 @@ namespace SHADE for (uint32_t i = 0; i < layouts.size(); ++i) { vkLayouts[i] = layouts[i]->GetVkHandle(); - setIndexing.emplace(layouts[i]->GetSetIndex(), i); } // Check for variable descriptor count @@ -87,7 +86,7 @@ namespace SHADE for (auto& binding : bindings) { BindingAndSetHash writeHash = binding.BindPoint; - writeHash |= static_cast(layouts[i]->GetSetIndex()) << 32; + writeHash |= static_cast(i) << 32; // new write for the binding updater.writeInfos.emplace_back(); @@ -208,16 +207,13 @@ namespace SHADE // Get binding + set hash BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); - // to index a set - uint32_t setIndex = setIndexing[set]; - // to index a write for a binding uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; // Initialize info for write - writeDescSet.descriptorType = layoutsUsed[setIndex]->GetBindings()[binding].Type; + writeDescSet.descriptorType = layoutsUsed[set]->GetBindings()[binding].Type; writeDescSet.dstArrayElement = 0; - writeDescSet.dstSet = descSets[setIndex]; + writeDescSet.dstSet = descSets[set]; writeDescSet.dstBinding = binding; writeDescSet.pImageInfo = updater.writeInfos[writeInfoIndex].descImageInfos.data(); @@ -233,16 +229,13 @@ namespace SHADE // Get binding + set hash BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); - // to index a set - uint32_t setIndex = setIndexing[set]; - // to index a write for a binding uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; // Initialize info for write - writeDescSet.descriptorType = layoutsUsed[setIndex]->GetBindings()[binding].Type; + writeDescSet.descriptorType = layoutsUsed[set]->GetBindings()[binding].Type; writeDescSet.dstArrayElement = 0; - writeDescSet.dstSet = descSets[setIndex]; + writeDescSet.dstSet = descSets[set]; writeDescSet.dstBinding = binding; writeDescSet.pBufferInfo = updater.writeInfos[writeInfoIndex].descBufferInfos.data(); diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h index 3f42afcc..a228bc66 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h @@ -21,7 +21,6 @@ namespace SHADE class SHVkImageView; class SHVkBuffer; - /*---------------------------------------------------------------------------------*/ /* Type Definitions */ /*---------------------------------------------------------------------------------*/ @@ -91,10 +90,10 @@ namespace SHADE //! Descriptor pool to allocate descriptor sets Handle descPool; - //! Sometimes when we pass in a layout, the set of the layout used in the - //! shader cannot be used to index into descSets. This is to mitigate that issue - //! when we update descriptor sets. - std::unordered_map setIndexing; + ////! Sometimes when we pass in a layout, the set of the layout used in the + ////! shader cannot be used to index into descSets. This is to mitigate that issue + ////! when we update descriptor sets. + //std::unordered_map setIndexing; //! Descriptor sets std::vector descSets; diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.cpp index 4be8cc9e..9b921411 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.cpp @@ -5,146 +5,138 @@ namespace SHADE { - /*---------------------------------------------------------------------------------*/ - /* Constructor/Destructor */ - /*---------------------------------------------------------------------------------*/ - SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(Handle device, SetIndex set, const std::vector& bindings, bool genImmutableSamplers/* = false*/) - : device { device } - , layoutDesc { bindings } - , setIndex {set} + /*---------------------------------------------------------------------------------*/ + /* Constructor/Destructor */ + /*---------------------------------------------------------------------------------*/ + SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(Handle device, const std::vector& bindings, bool genImmutableSamplers/* = false*/) + : device{ device } + , layoutDesc{ bindings } , immutableSampler{} + { + // Check if auto-binding point calculation configuration is valid + bool autoCalc = false; + for (const auto& binding : bindings) { - // Check if auto-binding point calculation configuration is valid - bool autoCalc = false; - for (const auto& binding : bindings) - { - if (binding.BindPoint == Binding::AUTO_CALC_BINDING) - { - autoCalc = true; - } - else if (autoCalc) - { - throw std::invalid_argument("For auto calculation of bindings, all bindings must be set to AUTO_CALC_BINDING!"); - } - } - - vk::Sampler tempVkSampler = nullptr; - if (genImmutableSamplers) - { - // Create sampler - immutableSampler = device->CreateSampler( - { - .minFilter = vk::Filter::eLinear, - .magFilter = vk::Filter::eLinear, - .addressMode = vk::SamplerAddressMode::eRepeat, - .mipmapMode = vk::SamplerMipmapMode::eLinear, - .minLod = -1000, - .maxLod = 1000 - } - ); - - tempVkSampler = immutableSampler->GetVkSampler(); - } - - - // Fill up VK bindings with auto calculated bind points if needed - std::vector layoutBindings; - layoutBindings.reserve(bindings.size()); - int bindCount = 0; - for (const auto& binding : bindings) - { - const uint32_t CURR_BIND_POINT = autoCalc ? bindCount : binding.BindPoint; - const vk::DescriptorSetLayoutBinding VK_BINDING = - { - .binding = CURR_BIND_POINT, - .descriptorType = binding.Type, - .descriptorCount = binding.DescriptorCount, - .stageFlags = binding.Stage, - .pImmutableSamplers = genImmutableSamplers ? &tempVkSampler : nullptr, - }; - layoutBindings.emplace_back(VK_BINDING); - - // Save for future reference - layoutDesc[bindCount++].BindPoint = CURR_BIND_POINT; - } - - // TODO: Check layout support with physical device - - // Prepare binding flags - std::vector combinedBindings(bindings.size()); - for (uint32_t i = 0; i < bindings.size(); ++i) - combinedBindings[i] = bindings[i].flags; - - const vk::DescriptorSetLayoutBindingFlagsCreateInfo BINDING_FLAGS_CREATE_INFO - { - .bindingCount = static_cast(bindings.size()), // Number of flags = number of bindings - .pBindingFlags = combinedBindings.data(), // address to flags - }; - - // Create the layout - const vk::DescriptorSetLayoutCreateInfo DESC_SET_LAYOUT_CREATE_INFO - { - .pNext = &BINDING_FLAGS_CREATE_INFO, - .flags = {}, - .bindingCount = static_cast(layoutBindings.size()), - .pBindings = layoutBindings.data(), - }; - setLayout = device->GetVkLogicalDevice().createDescriptorSetLayout(DESC_SET_LAYOUT_CREATE_INFO); - } - - SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept - : device {rhs.device} - , setLayout {rhs.setLayout} - , layoutDesc{std::move (rhs.layoutDesc)} - , setIndex{ rhs.setIndex } - , immutableSampler{ rhs.immutableSampler } - { - rhs.setLayout = VK_NULL_HANDLE; - } - - SHVkDescriptorSetLayout::~SHVkDescriptorSetLayout() noexcept - { - // Destroy layout - if (setLayout) - device->GetVkLogicalDevice().destroyDescriptorSetLayout(setLayout); - } - - std::vector const& SHVkDescriptorSetLayout::GetBindings(void) const noexcept - { - return layoutDesc; - } - - SetIndex SHVkDescriptorSetLayout::GetSetIndex(void) const noexcept - { - return setIndex; - } - - uint32_t SHVkDescriptorSetLayout::GetNumDynamicOffsetsRequired(void) const noexcept - { - uint32_t numDynamicBindings = 0; - for (auto& binding : layoutDesc) + if (binding.BindPoint == Binding::AUTO_CALC_BINDING) { - if (binding.Type == vk::DescriptorType::eUniformBufferDynamic || binding.Type == vk::DescriptorType::eStorageBufferDynamic) - ++numDynamicBindings; + autoCalc = true; + } + else if (autoCalc) + { + throw std::invalid_argument("For auto calculation of bindings, all bindings must be set to AUTO_CALC_BINDING!"); } - - return numDynamicBindings; } - SHVkDescriptorSetLayout& SHVkDescriptorSetLayout::operator=(SHVkDescriptorSetLayout&& rhs) noexcept + vk::Sampler tempVkSampler = nullptr; + if (genImmutableSamplers) { - if (&rhs == this) - return *this; + // Create sampler + immutableSampler = device->CreateSampler( + { + .minFilter = vk::Filter::eLinear, + .magFilter = vk::Filter::eLinear, + .addressMode = vk::SamplerAddressMode::eRepeat, + .mipmapMode = vk::SamplerMipmapMode::eLinear, + .minLod = -1000, + .maxLod = 1000 + } + ); - device = rhs.device; - setLayout = rhs.setLayout; - layoutDesc = std::move(rhs.layoutDesc); - setIndex = rhs.setIndex; - immutableSampler = rhs.immutableSampler; - - rhs.setLayout = VK_NULL_HANDLE; - - return *this; + tempVkSampler = immutableSampler->GetVkSampler(); } + + // Fill up VK bindings with auto calculated bind points if needed + std::vector layoutBindings; + layoutBindings.reserve(bindings.size()); + int bindCount = 0; + for (const auto& binding : bindings) + { + const uint32_t CURR_BIND_POINT = autoCalc ? bindCount : binding.BindPoint; + const vk::DescriptorSetLayoutBinding VK_BINDING = + { + .binding = CURR_BIND_POINT, + .descriptorType = binding.Type, + .descriptorCount = binding.DescriptorCount, + .stageFlags = binding.Stage, + .pImmutableSamplers = genImmutableSamplers ? &tempVkSampler : nullptr, + }; + layoutBindings.emplace_back(VK_BINDING); + + // Save for future reference + layoutDesc[bindCount++].BindPoint = CURR_BIND_POINT; + } + + // TODO: Check layout support with physical device + + // Prepare binding flags + std::vector combinedBindings(bindings.size()); + for (uint32_t i = 0; i < bindings.size(); ++i) + combinedBindings[i] = bindings[i].flags; + + const vk::DescriptorSetLayoutBindingFlagsCreateInfo BINDING_FLAGS_CREATE_INFO + { + .bindingCount = static_cast(bindings.size()), // Number of flags = number of bindings + .pBindingFlags = combinedBindings.data(), // address to flags + }; + + // Create the layout + const vk::DescriptorSetLayoutCreateInfo DESC_SET_LAYOUT_CREATE_INFO + { + .pNext = &BINDING_FLAGS_CREATE_INFO, + .flags = {}, + .bindingCount = static_cast(layoutBindings.size()), + .pBindings = layoutBindings.data(), + }; + setLayout = device->GetVkLogicalDevice().createDescriptorSetLayout(DESC_SET_LAYOUT_CREATE_INFO); + } + + SHVkDescriptorSetLayout::SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept + : device{ rhs.device } + , setLayout{ rhs.setLayout } + , layoutDesc{ std::move(rhs.layoutDesc) } + , immutableSampler{ rhs.immutableSampler } + { + rhs.setLayout = VK_NULL_HANDLE; + } + + SHVkDescriptorSetLayout::~SHVkDescriptorSetLayout() noexcept + { + // Destroy layout + if (setLayout) + device->GetVkLogicalDevice().destroyDescriptorSetLayout(setLayout); + } + + std::vector const& SHVkDescriptorSetLayout::GetBindings(void) const noexcept + { + return layoutDesc; + } + + uint32_t SHVkDescriptorSetLayout::GetNumDynamicOffsetsRequired(void) const noexcept + { + uint32_t numDynamicBindings = 0; + for (auto& binding : layoutDesc) + { + if (binding.Type == vk::DescriptorType::eUniformBufferDynamic || binding.Type == vk::DescriptorType::eStorageBufferDynamic) + ++numDynamicBindings; + } + + return numDynamicBindings; + } + + SHVkDescriptorSetLayout& SHVkDescriptorSetLayout::operator=(SHVkDescriptorSetLayout&& rhs) noexcept + { + if (&rhs == this) + return *this; + + device = rhs.device; + setLayout = rhs.setLayout; + layoutDesc = std::move(rhs.layoutDesc); + immutableSampler = rhs.immutableSampler; + + rhs.setLayout = VK_NULL_HANDLE; + + return *this; + } + } diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h index caa3c057..f0e1fe4e 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h @@ -6,109 +6,107 @@ namespace SHADE { - /*---------------------------------------------------------------------------------*/ - /* Forward Declarations */ - /*---------------------------------------------------------------------------------*/ - class SHVkLogicalDevice; - class SHVkSampler; + /*---------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*---------------------------------------------------------------------------------*/ + class SHVkLogicalDevice; + class SHVkSampler; - /*---------------------------------------------------------------------------------*/ - /* Type Definitions */ - /*---------------------------------------------------------------------------------*/ + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + /// + /// RAII wrapper object for a Vulkan Descriptor Set Layout object. + /// + class SHVkDescriptorSetLayout + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ /// - /// RAII wrapper object for a Vulkan Descriptor Set Layout object. + /// Object that describes how a descriptor binding in a DescriptorSetLayout is + /// structured. /// - class SHVkDescriptorSetLayout + struct Binding { - public: - /*-----------------------------------------------------------------------------*/ - /* Type Definitions */ - /*-----------------------------------------------------------------------------*/ - /// - /// Object that describes how a descriptor binding in a DescriptorSetLayout is - /// structured. - /// - struct Binding - { - /*-------------------------------------------------------------------------*/ - /* Constants */ - /*-------------------------------------------------------------------------*/ - /// - /// If set for the "BindPoint", binding points are automatically calculated. - /// - static constexpr uint32_t AUTO_CALC_BINDING = std::numeric_limits::max(); + /*-------------------------------------------------------------------------*/ + /* Constants */ + /*-------------------------------------------------------------------------*/ + /// + /// If set for the "BindPoint", binding points are automatically calculated. + /// + static constexpr uint32_t AUTO_CALC_BINDING = std::numeric_limits::max(); - /// - /// For use in Binding DescriptorCount. - /// - static constexpr uint32_t VARIABLE_DESCRIPTOR_UPPER_BOUND = 2000; - /*-------------------------------------------------------------------------*/ - /* Data Members */ - /*-------------------------------------------------------------------------*/ - /// - /// Type of element for the descriptor. - /// - vk::DescriptorType Type = {}; - /// - /// Shader stage that this binding is for. - /// - vk::ShaderStageFlags Stage = {}; - /// - /// Binding point for the Descriptor within the Descriptor Set. - /// - uint32_t BindPoint = AUTO_CALC_BINDING; - /// - /// Number of elements in the binding. When VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT - /// is used in VkDescriptorBindingFlagBits, this value represents the upper bound. - /// - uint32_t DescriptorCount = 1; + /// + /// For use in Binding DescriptorCount. + /// + static constexpr uint32_t VARIABLE_DESCRIPTOR_UPPER_BOUND = 2000; + /*-------------------------------------------------------------------------*/ + /* Data Members */ + /*-------------------------------------------------------------------------*/ + /// + /// Type of element for the descriptor. + /// + vk::DescriptorType Type = {}; + /// + /// Shader stage that this binding is for. + /// + vk::ShaderStageFlags Stage = {}; + /// + /// Binding point for the Descriptor within the Descriptor Set. + /// + uint32_t BindPoint = AUTO_CALC_BINDING; + /// + /// Number of elements in the binding. When VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT + /// is used in VkDescriptorBindingFlagBits, this value represents the upper bound. + /// + uint32_t DescriptorCount = 1; - vk::DescriptorBindingFlags flags = {}; - }; - - /*-----------------------------------------------------------------------------*/ - /* Constructor/Destructors */ - /*-----------------------------------------------------------------------------*/ - SHVkDescriptorSetLayout() = delete; - /// - /// Constructs a DescriptorSetLayout with the specified properties and device. - /// - /// - /// - SHVkDescriptorSetLayout(Handle device, SetIndex setIndex, const std::vector& bindings, bool genImmutableSamplers = false); - SHVkDescriptorSetLayout(const SHVkDescriptorSetLayout&) = delete; - SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept; - /// - /// Destructor which will unload and deallocate all resources for this Set. - /// - ~SHVkDescriptorSetLayout() noexcept; - - /*-----------------------------------------------------------------------------*/ - /* Overloaded Operators */ - /*-----------------------------------------------------------------------------*/ - SHVkDescriptorSetLayout& operator=(const SHVkDescriptorSetLayout&) = delete; - SHVkDescriptorSetLayout& operator=(SHVkDescriptorSetLayout&& rhs) noexcept; - - /*-----------------------------------------------------------------------------*/ - /* Getter Functions */ - /*-----------------------------------------------------------------------------*/ - /// - /// Retrieves the handle to the Vulkan Descriptor Set Layout handle. - /// - /// Handle to the Vulkan Descriptor Set Layout handle. - inline const vk::DescriptorSetLayout& GetVkHandle() const { return setLayout; } - std::vector const& GetBindings (void) const noexcept; - SetIndex GetSetIndex (void) const noexcept; - uint32_t GetNumDynamicOffsetsRequired (void) const noexcept; - - private: - /*-----------------------------------------------------------------------------*/ - /* Data Members */ - /*-----------------------------------------------------------------------------*/ - Handle device; - vk::DescriptorSetLayout setLayout; - std::vector layoutDesc; // Stores description of the layout - SetIndex setIndex; // Index of the set - Handle immutableSampler; + vk::DescriptorBindingFlags flags = {}; }; + + /*-----------------------------------------------------------------------------*/ + /* Constructor/Destructors */ + /*-----------------------------------------------------------------------------*/ + SHVkDescriptorSetLayout() = delete; + /// + /// Constructs a DescriptorSetLayout with the specified properties and device. + /// + /// + /// + SHVkDescriptorSetLayout(Handle device, const std::vector& bindings, bool genImmutableSamplers = false); + SHVkDescriptorSetLayout(const SHVkDescriptorSetLayout&) = delete; + SHVkDescriptorSetLayout(SHVkDescriptorSetLayout&& rhs) noexcept; + /// + /// Destructor which will unload and deallocate all resources for this Set. + /// + ~SHVkDescriptorSetLayout() noexcept; + + /*-----------------------------------------------------------------------------*/ + /* Overloaded Operators */ + /*-----------------------------------------------------------------------------*/ + SHVkDescriptorSetLayout& operator=(const SHVkDescriptorSetLayout&) = delete; + SHVkDescriptorSetLayout& operator=(SHVkDescriptorSetLayout&& rhs) noexcept; + + /*-----------------------------------------------------------------------------*/ + /* Getter Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Retrieves the handle to the Vulkan Descriptor Set Layout handle. + /// + /// Handle to the Vulkan Descriptor Set Layout handle. + inline const vk::DescriptorSetLayout& GetVkHandle() const { return setLayout; } + std::vector const& GetBindings(void) const noexcept; + uint32_t GetNumDynamicOffsetsRequired(void) const noexcept; + + private: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Handle device; + vk::DescriptorSetLayout setLayout; + std::vector layoutDesc; // Stores description of the layout + Handle immutableSampler; + }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 95cf2e91..6a6e385f 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -561,9 +561,9 @@ namespace SHADE } - Handle SHVkLogicalDevice::CreateDescriptorSetLayout(SetIndex setIndex, std::vector const& bindings, bool genImmutableSamplers/* = false*/) noexcept + Handle SHVkLogicalDevice::CreateDescriptorSetLayout(std::vector const& bindings, bool genImmutableSamplers/* = false*/) noexcept { - return SHVkInstance::GetResourceManager().Create (GetHandle(), setIndex, bindings, genImmutableSamplers); + return SHVkInstance::GetResourceManager().Create (GetHandle(), bindings, genImmutableSamplers); } Handle SHVkLogicalDevice::CreateDescriptorPools(const SHVkDescriptorPool::Config& config /*= {}*/) noexcept diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h index ed09b482..6e3bb0ce 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h @@ -190,7 +190,7 @@ namespace SHADE Handle CreateRenderpass (std::span const vkDescriptions, std::vector const& subpasses) noexcept; Handle CreateRenderpass (std::span const vkDescriptions, std::span const spDescs, std::span const spDeps) noexcept; Handle CreateFramebuffer (Handle const& renderpassHdl, std::vector> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept; - Handle CreateDescriptorSetLayout (SetIndex setIndex, std::vector const& bindings, bool genImmutableSamplers = false) noexcept; + Handle CreateDescriptorSetLayout (std::vector const& bindings, bool genImmutableSamplers = false) noexcept; Handle CreateDescriptorPools (const SHVkDescriptorPool::Config& config = {}) noexcept; Handle CreateDescriptorSetGroup(Handle pool, std::vector> const& layouts, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 211c50b7..cb2806aa 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -25,7 +25,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "ECS_Base/Managers/SHComponentManager.h" #include "Math/Transform/SHTransformComponent.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Scene/SHSceneManager.h" #include "UI/SHUIComponent.h" @@ -607,7 +607,7 @@ namespace SHADE { matPropsDescSet[frameIndex] = descPool->Allocate ( - { SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] }, + { SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] }, { 0 } ); #ifdef _DEBUG diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp similarity index 63% rename from SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp rename to SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp index 87234a6b..d93e073b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp @@ -1,30 +1,24 @@ #include "SHpch.h" -#include "SHGraphicsGlobalData.h" +#include "SHPredefinedData.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h" #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/MiddleEnd/Lights/SHLightData.h" -#include "Tools/Utilities/SHUtilities.h" namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Static Definitions */ /*-----------------------------------------------------------------------------------*/ - std::vector> SHGraphicsGlobalData::globalDescSetLayouts; - SHVertexInputState SHGraphicsGlobalData::defaultVertexInputState; - Handle SHGraphicsGlobalData::dummyPipelineLayout; - - void SHGraphicsGlobalData::InitHighFrequencyGlobalData(void) noexcept - { - - } + std::vector> SHPredefinedData::predefinedLayouts; + SHVertexInputState SHPredefinedData::defaultVertexInputState; + Handle SHPredefinedData::dummyPipelineLayout; /*-----------------------------------------------------------------------------------*/ /* Function Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHGraphicsGlobalData::InitDescSetLayouts(Handle logicalDevice) noexcept + void SHPredefinedData::InitDescSetLayouts(Handle logicalDevice) noexcept { SHVkDescriptorSetLayout::Binding genericDataBinding { @@ -44,7 +38,7 @@ namespace SHADE }; // For global data (generic data and textures) - Handle staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS, { genericDataBinding, texturesBinding }); + Handle staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ genericDataBinding, texturesBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, staticGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] Static Globals"); @@ -72,8 +66,8 @@ namespace SHADE } // For Dynamic global data (lights) - Handle dynamicGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, lightBindings); - SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, dynamicGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] Dynamic Globals"); + Handle lightDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout(lightBindings); + SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, lightDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Dynamic Globals"); // For High frequency global data (camera) SHVkDescriptorSetLayout::Binding cameraDataBinding @@ -83,7 +77,7 @@ namespace SHADE .BindPoint = SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, .DescriptorCount = 1, }; - Handle cameraDataGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, { cameraDataBinding }); + Handle cameraDataGlobalLayout = logicalDevice->CreateDescriptorSetLayout({ cameraDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, cameraDataGlobalLayout->GetVkHandle(), "[Descriptor Set Layout] High Frequency Globals"); // For per instance data (transforms, materials, etc.) @@ -94,21 +88,41 @@ namespace SHADE .BindPoint = SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, .DescriptorCount = 1, }; - Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, { materialDataBinding }); + Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); + // font bitmap data (texture) + SHVkDescriptorSetLayout::Binding fontBitmapBinding + { + .Type = vk::DescriptorType::eCombinedImageSampler, + .Stage = vk::ShaderStageFlagBits::eFragment, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, + .DescriptorCount = 1, + }; + + // font data in the form of matrices + SHVkDescriptorSetLayout::Binding fontMatrixBinding + { + .Type = vk::DescriptorType::eStorageBuffer, + .Stage = vk::ShaderStageFlagBits::eVertex, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, + .DescriptorCount = 1, + }; + + Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); + SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); - globalDescSetLayouts.push_back(staticGlobalLayout); - globalDescSetLayouts.push_back(dynamicGlobalLayout); - globalDescSetLayouts.push_back(cameraDataGlobalLayout); - globalDescSetLayouts.push_back(materialDataPerInstanceLayout); + predefinedLayouts.push_back(staticGlobalLayout); + predefinedLayouts.push_back(lightDataDescSetLayout); + predefinedLayouts.push_back(cameraDataGlobalLayout); + predefinedLayouts.push_back(materialDataPerInstanceLayout); + predefinedLayouts.push_back(fontDataDescSetLayout); - - dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{globalDescSetLayouts}); + dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{predefinedLayouts}); } - void SHGraphicsGlobalData::InitDefaultVertexInputState(void) noexcept + void SHPredefinedData::InitDefaultVertexInputState(void) noexcept { defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 @@ -118,24 +132,31 @@ namespace SHADE defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8 } - void SHGraphicsGlobalData::Init(Handle logicalDevice) noexcept + void SHPredefinedData::Init(Handle logicalDevice) noexcept { InitDescSetLayouts(logicalDevice); InitDefaultVertexInputState(); } - std::vector> const& SHGraphicsGlobalData::GetDescSetLayouts(void) noexcept + std::vector> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept { - return globalDescSetLayouts; + std::vector> layoutsFound; + for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i) + { + if (types & (static_cast(1) << i)) + layoutsFound.push_back(predefinedLayouts[i]); + } + + return layoutsFound; } - SHVertexInputState const& SHGraphicsGlobalData::GetDefaultViState(void) noexcept + SHVertexInputState const& SHPredefinedData::GetDefaultViState(void) noexcept { return defaultVertexInputState; } - Handle SHGraphicsGlobalData::GetDummyPipelineLayout(void) noexcept + Handle SHPredefinedData::GetDummyPipelineLayout(void) noexcept { return dummyPipelineLayout; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h similarity index 76% rename from SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h rename to SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h index 439acba5..5f13a100 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h @@ -3,6 +3,7 @@ #include "SH_API.h" #include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "Tools/Utilities/SHUtilities.h" namespace SHADE { @@ -11,11 +12,11 @@ namespace SHADE class SHVkDescriptorSetGroup; class SHVkPipelineLayout; - class SH_API SHGraphicsGlobalData + class SH_API SHPredefinedData { private: //! Global descriptor set layouts. Used to allocate descriptor sets - static std::vector> globalDescSetLayouts; + static std::vector> predefinedLayouts; //! Default vertex input state (used by everything). static SHVertexInputState defaultVertexInputState; @@ -24,7 +25,6 @@ namespace SHADE //! we create a dummy pipeline layout to use it for binding. static Handle dummyPipelineLayout; - static void InitHighFrequencyGlobalData (void) noexcept; static void InitDescSetLayouts (Handle logicalDevice) noexcept; static void InitDefaultVertexInputState (void) noexcept; @@ -32,7 +32,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* Constructors */ /*-----------------------------------------------------------------------*/ - SHGraphicsGlobalData() = delete; + SHPredefinedData() = delete; /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ @@ -42,8 +42,8 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static std::vector> const& GetDescSetLayouts (void) noexcept; - static SHVertexInputState const& GetDefaultViState (void) noexcept; - static Handle GetDummyPipelineLayout (void) noexcept; + static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; + static SHVertexInputState const& GetDefaultViState (void) noexcept; + static Handle GetDummyPipelineLayout (void) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index e6051841..e0b76555 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -25,74 +25,85 @@ namespace SHADE struct SHGraphicsConstants { public: + static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64; + + enum class SHPredefinedDescSetLayoutTypes : uint64_t + { + STATIC_DATA = 0x01, + LIGHTS = 0x02, + CAMERA = 0x04, + MATERIALS = 0x08, + FONT = 0x10, + }; + struct RenderGraphIndices { static constexpr uint32_t WORLD = 0; static constexpr uint32_t EDITOR = 0; }; - struct DescriptorSetIndex - { - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for static global values like generic data, and - texture samplers - */ - /***************************************************************************/ - static constexpr uint32_t STATIC_GLOBALS = 0; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for dynamic global values like lights. - */ - /***************************************************************************/ - static constexpr uint32_t DYNAMIC_GLOBALS = 1; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for high frequency changing global values like - camera matrices. - */ - /***************************************************************************/ - static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for per-instance/material changing values. - */ - /***************************************************************************/ - static constexpr uint32_t PER_INSTANCE = 3; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for render graph resources. Unlike the sets from - 1 to 3 and 6, this set index does not have hard coded bindings and is - NOT part of the layouts included in the global data. - */ - /***************************************************************************/ - static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for render graph node compute resources. For data - that we wish to pass to compute shaders in the render graph, this is - the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have - hard coded bindings and is NOT part of the layouts included in the global - data. - */ - /***************************************************************************/ - static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; + //struct DescriptorSetIndex + //{ + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for static global values like generic data, and + // texture samplers + // */ + // /***************************************************************************/ + // static constexpr uint32_t STATIC_GLOBALS = 0; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for dynamic global values like lights. + // */ + // /***************************************************************************/ + // static constexpr uint32_t DYNAMIC_GLOBALS = 1; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for high frequency changing global values like + // camera matrices. + // */ + // /***************************************************************************/ + // static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for per-instance/material changing values. + // */ + // /***************************************************************************/ + // static constexpr uint32_t PER_INSTANCE = 3; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for render graph resources. Unlike the sets from + // 1 to 3 and 6, this set index does not have hard coded bindings and is + // NOT part of the layouts included in the global data. + // */ + // /***************************************************************************/ + // static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for render graph node compute resources. For data + // that we wish to pass to compute shaders in the render graph, this is + // the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have + // hard coded bindings and is NOT part of the layouts included in the global + // data. + // */ + // /***************************************************************************/ + // static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; - /***************************************************************************/ - /*! - \brief - To store font data. - - */ - /***************************************************************************/ - static constexpr uint32_t FONT_DATA = 4; - }; + // /***************************************************************************/ + // /*! + // \brief + // To store font data. + // + // */ + // /***************************************************************************/ + // static constexpr uint32_t FONT_DATA = 4; + //}; struct DescriptorSetBindings { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 9a599a07..c9e7f2d2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -31,7 +31,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" #include "SHGraphicsConstants.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" #include "Assets/Asset Types/SHTextureAsset.h" @@ -124,6 +124,9 @@ namespace SHADE SHFreetypeInstance::Init(); + SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_FS.glsl", false); + // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); @@ -318,12 +321,12 @@ namespace SHADE /* 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 = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[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 = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph); screenRenderer->SetCamera(screenCamera); screenRenderer->SetCameraDirector(worldCameraDirector); @@ -356,7 +359,7 @@ namespace SHADE void SHGraphicsSystem::InitMiddleEnd(void) noexcept { - SHGraphicsGlobalData::Init(device); + SHPredefinedData::Init(device); InitSceneRenderGraph(); @@ -454,7 +457,7 @@ namespace SHADE editorRenderGraph->Generate(); // Add world renderer to default viewport - editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph); + editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph); editorRenderer->SetCamera(worldCamera); } #endif @@ -567,8 +570,8 @@ namespace SHADE currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); // Force set the pipeline layout - currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); - currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE); + currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); + currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE); // Bind all the buffers required for meshes for (auto& [buffer, bindingPoint] : MESH_DATA) @@ -900,7 +903,7 @@ namespace SHADE void SHGraphicsSystem::BuildFonts(void) noexcept { - fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, textRenderingSubSystem->GetFontDataDescSetLayout(), resourceManager); + fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::FONT)[0], resourceManager); } #pragma endregion ADD_REMOVE @@ -1044,6 +1047,10 @@ namespace SHADE graphSemaphores[0].Free(); graphSemaphores[1].Free(); + for (auto& semaHandle : graphSemaphores) + semaHandle = device->CreateSemaphore(); + + auto windowDims = window->GetWindowSize(); // Resize the swapchain @@ -1054,6 +1061,12 @@ namespace SHADE worldRenderGraph->HandleResize(resizeWidth, resizeHeight); #ifdef SHEDITOR + + // NOTE: These 2 lines are actually not necessary because the editor viewport is not even used for + // setting dynamic viewport or scissor state. ImGUI takes care of that for us. + //editorViewport->SetWidth(windowDims.first); + //editorViewport->SetHeight(windowDims.second); + editorRenderGraph->HandleResize(windowDims.first, windowDims.second); #endif @@ -1076,8 +1089,6 @@ namespace SHADE #endif - for (auto& semaHandle : graphSemaphores) - semaHandle = device->CreateSemaphore(); } void SHGraphicsSystem::AwaitGraphicsExecution() @@ -1126,7 +1137,7 @@ namespace SHADE device, SHPipelineLayoutParams { .shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader }, - .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() + .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::CAMERA) } ); auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index e47055df..1136a2c9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -51,9 +51,12 @@ namespace SHADE std::array cameraBufferArray{cameraBuffer}; - cameraDescriptorSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, std::span>{ cameraBufferArray.data(), cameraBufferArray.size()}, 0, sizeof (SHShaderCameraData)); + // We use index 0 because the descriptor set is standalone created from a single desc set layout. What the driver sees is that this set is at index 0 during updating. + static constexpr uint8_t SET_0 = 0; - cameraDescriptorSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA); + cameraDescriptorSet->ModifyWriteDescBuffer(SET_0, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA, std::span>{ cameraBufferArray.data(), cameraBufferArray.size()}, 0, sizeof (SHShaderCameraData)); + + cameraDescriptorSet->UpdateDescriptorSetBuffer(SET_0, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA); } SHRenderer::~SHRenderer(void) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 83291700..4bd205be 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -37,7 +37,7 @@ namespace SHADE class SHVkCommandBuffer; class SHCamera; class SHVkDescriptorSetGroup; - class SHGraphicsGlobalData; + class SHPredefinedData; class SHVkDescriptorPool; class SHVkBuffer; class SHCameraDirector; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 3d5a5773..448c3bed 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -1,6 +1,6 @@ #include "SHpch.h" #include "SHLightingSubSystem.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Tools/Utilities/SHUtilities.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Buffers/SHVkBuffer.h" @@ -385,7 +385,7 @@ namespace SHADE std::fill (variableSizes.begin(), variableSizes.end(), 1); // Create the descriptor set - lightingDataDescSet = descPool->Allocate({ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes); + lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes); #ifdef _DEBUG const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle(); for (int i = 0; i < static_cast(CAM_DESC_SETS.size()); ++i) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 05bd8813..9e6f1bd7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -1,7 +1,7 @@ #include "SHpch.h" #include "SHPipelineLibrary.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/SHVkUtil.h" @@ -13,7 +13,7 @@ namespace SHADE SHPipelineLayoutParams params { .shaderModules = {vsFsPair.first, vsFsPair.second}, - .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() + .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts() }; // Create the pipeline layout @@ -21,7 +21,7 @@ namespace SHADE // Create the pipeline and configure the default vertex input state auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass); - newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsGlobalData::GetDefaultViState()); + newPipeline->GetPipelineState().SetVertexInputState(SHPredefinedData::GetDefaultViState()); SHColorBlendState colorBlendState{}; colorBlendState.logic_op_enable = VK_FALSE; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h index aeb023c5..389f5fa8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h @@ -10,7 +10,7 @@ namespace SHADE class SHVkDescriptorSetLayouts; class SHVkPipeline; class SHSubpass; - class SHGraphicsGlobalData; + class SHPredefinedData; // Pipeline library is a PURELY MIDDLE END SYSTEM. It is responsible for only creating pipelines from shaders and caching // them so that they don't need to be recreated again. diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp index 3dd54ca5..f0273940 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp @@ -1,7 +1,7 @@ #include "SHpch.h" #include "SHFont.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index 6748311e..f0e375e6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -6,7 +6,7 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/TextRendering/SHFont.h" #include "Graphics/Buffers/SHVkBuffer.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/SHVkUtil.h" #include "Graphics/RenderGraph/SHSubpass.h" @@ -103,7 +103,7 @@ namespace SHADE SHPipelineLayoutParams plParams { .shaderModules = {textVS, textFS}, - .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() + .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts() }; pipelineLayout = logicalDevice->CreatePipelineLayout(plParams); @@ -157,24 +157,6 @@ namespace SHADE // Construct pipeline pipeline->ConstructPipeline(); - SHVkDescriptorSetLayout::Binding fontBitmapBinding - { - .Type = vk::DescriptorType::eCombinedImageSampler, - .Stage = vk::ShaderStageFlagBits::eFragment, - .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, - .DescriptorCount = 1, - }; - - SHVkDescriptorSetLayout::Binding fontMatrixBinding - { - .Type = vk::DescriptorType::eStorageBuffer, - .Stage = vk::ShaderStageFlagBits::eVertex, - .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, - .DescriptorCount = 1, - }; - - fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, { fontBitmapBinding, fontMatrixBinding }); - } void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept @@ -209,6 +191,7 @@ namespace SHADE cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); + // bind camera desc set (again). Necessary because pipeline layout is not compatible. cameraDescSetBind(cmdBuffer, frameIndex); // bind descriptors for font (matrices) @@ -234,9 +217,9 @@ namespace SHADE } - Handle SHTextRenderingSubSystem::GetFontDataDescSetLayout(void) const noexcept - { - return fontDataDescSetLayout; - } + //Handle SHTextRenderingSubSystem::GetFontDataDescSetLayout(void) const noexcept + //{ + // return fontDataDescSetLayout; + //} } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index 05ab01da..78b363d4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -41,7 +41,7 @@ namespace SHADE Handle pipelineLayout; //! Descriptor set for font data access in shaders - Handle fontDataDescSetLayout; + //Handle fontDataDescSetLayout; //! Super temporary. Global descriptor set needs to be revamped along with //! entire graphics system. @@ -58,7 +58,7 @@ namespace SHADE void Exit(void) noexcept; - Handle GetFontDataDescSetLayout (void) const noexcept; + //Handle GetFontDataDescSetLayout (void) const noexcept; }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index dfb3f3b9..a31f54de 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -24,7 +24,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Images/SHVkImage.h" #include "Graphics/Images/SHVkImageView.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Assets/Asset Types/SHTextureAsset.h" namespace SHADE @@ -168,7 +168,7 @@ namespace SHADE } texDescriptors = descPool->Allocate ( - { SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] }, + { SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] }, { static_cast(texOrder.size()) } ); #ifdef _DEBUG diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 2ffd6d13..fc029161 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -12,7 +12,7 @@ #include "SHRenderGraphStorage.h" #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "Tools/Utilities/SHUtilities.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 0a9ed376..f892483f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -29,7 +29,7 @@ namespace SHADE class SHVkCommandPool; class SHVkCommandBuffer; class SHRenderGraphNode; - class SHGraphicsGlobalData; + class SHPredefinedData; class SHVkDescriptorPool; class SHRenderGraphStorage; class SHRenderToSwapchainImageSystem; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 775d64f7..2311ee0c 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -19,7 +19,7 @@ namespace SHADE class SHVkLogicalDevice; class SHVkRenderpass; class SHVkDescriptorPool; - class SHGraphicsGlobalData; + class SHPredefinedData; class SHRenderGraphStorage; class SHRenderGraphNodeCompute; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index 2f8fd968..aca987d8 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -6,7 +6,7 @@ #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "SHRenderGraphStorage.h" #include "SHRenderGraphResource.h" #include "Graphics/Commands/SHVkCommandBuffer.h" @@ -27,7 +27,7 @@ namespace SHADE SHPipelineLayoutParams pipelineLayoutParams { .shaderModules = {computeShaderModule}, - .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(), + .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(), .dynamicBufferBindings = std::move(dynamicBufferBindings), }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h index d02d8d39..d473dd2a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h @@ -7,7 +7,7 @@ namespace SHADE { class SHVkLogicalDevice; class SHVkSwapchain; - class SHGraphicsGlobalData; + class SHPredefinedData; class SHVkDescriptorPool; class SHRenderGraphResource; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp index 770217ee..b8717925 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp @@ -1,7 +1,7 @@ #include "SHpch.h" #include "SHRenderToSwapchainImageSystem.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/RenderGraph/SHRenderGraphNode.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/SHVkUtil.h" @@ -24,7 +24,7 @@ namespace SHADE auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams { .shaderModules = {shaderModules.first, shaderModules.second}, - .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(), + .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(), }); pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); diff --git a/SHADE_Engine/src/Tools/Utilities/SHUtilities.h b/SHADE_Engine/src/Tools/Utilities/SHUtilities.h index 6cdd91ee..c3492f13 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHUtilities.h +++ b/SHADE_Engine/src/Tools/Utilities/SHUtilities.h @@ -43,6 +43,73 @@ namespace SHADE static constexpr OutputType ConvertEnum(InputType enumClassMember) noexcept; }; + template + class SHEnumWrapper + { + public: + using UnderlyingType = typename std::underlying_type_t; + + private: + UnderlyingType mask; + + public: + + constexpr SHEnumWrapper(void) noexcept + : mask{ 0 } + { + + }; + + constexpr SHEnumWrapper(BitType bit) noexcept + : mask{ static_cast(bit) } + { + + }; + + constexpr SHEnumWrapper(SHEnumWrapper const& rhs) noexcept = default; + constexpr SHEnumWrapper& operator= (SHEnumWrapper const& rhs) noexcept = default; + + constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept + : mask{ flags } + { + + }; + + constexpr SHEnumWrapper operator| (SHEnumWrapper const& rhs) const noexcept + { + return static_cast> (mask | rhs.mask); + }; + + constexpr SHEnumWrapper operator& (SHEnumWrapper const& rhs) const noexcept + { + return static_cast> (mask & rhs.mask); + }; + + constexpr operator UnderlyingType() const noexcept + { + return mask; + }; + }; + + template>> + inline BitType operator|(const BitType& left, const BitType& right) + { + return static_cast(static_cast(left) | static_cast(right)); + } + + template>> + inline BitType operator&(const BitType& left, const BitType& right) + { + return static_cast(static_cast(left) & static_cast(right)); + } + + template + std::ostream& operator<<(std::ostream& os, EnumType const& type) + { + os << static_cast(type); + return os; + } + } // namespace SHADE #include "SHUtilities.hpp" From 5f2fa7fdf5d0b0d6ff8dc0a50ff9e1050f408d99 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 26 Dec 2022 09:28:15 +0800 Subject: [PATCH 09/24] WIP - Created a class that allows custom mappings of descriptor types to set indices - SHPredefinedData now contains objects of the above class with predefined mappings for the different sub systems in the Graphics System. - These mappings are also accompanied with descriptor set layout vectors that are only for that system. This helps the sub systems have access to these layouts easily without having to pass them around. - Created another class to manage global descriptor sets such as lights. - Modified pipeline layout creation code to take in the correct descriptor set layouts. --- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 18 ++- .../GlobalData/SHDescriptorMappings.cpp | 17 +++ .../GlobalData/SHDescriptorMappings.h | 29 ++++ .../GlobalData/SHGlobalDescriptorSets.cpp | 30 ++++ .../GlobalData/SHGlobalDescriptorSets.h | 24 +++ .../MiddleEnd/GlobalData/SHPredefinedData.cpp | 106 ++++++++++--- .../MiddleEnd/GlobalData/SHPredefinedData.h | 36 ++++- .../MiddleEnd/Interface/SHGraphicsConstants.h | 141 ++++++++++-------- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 4 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 2 +- .../SHTextRenderingSubSystem.cpp | 2 +- .../Pipeline/SHPipelineLayoutParams.h | 2 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 34 +++-- .../SHRenderToSwapchainImageSystem.cpp | 2 +- 14 files changed, 329 insertions(+), 118 deletions(-) create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index cb2806aa..c92ad808 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -411,11 +411,12 @@ namespace SHADE instancedIntegerData.reserve(numTotalElements); instancedIntegerData.clear(); + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; // - Material Properties Data const Handle SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, vk::ShaderStageFlagBits::eFragment ); @@ -570,11 +571,14 @@ namespace SHADE cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0); if (matPropsDescSet[frameIndex]) { + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + cmdBuffer->BindDescriptorSet ( matPropsDescSet[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), dynamicOffset ); } @@ -607,7 +611,7 @@ namespace SHADE { matPropsDescSet[frameIndex] = descPool->Allocate ( - { SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] }, + SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS), { 0 } ); #ifdef _DEBUG @@ -618,17 +622,21 @@ namespace SHADE } #endif } + + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + uint32_t const MATERIAL_DESC_SET_INDEX = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS); + std::array, 1> bufferList = { matPropsBuffer[frameIndex] }; matPropsDescSet[frameIndex]->ModifyWriteDescBuffer ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + MATERIAL_DESC_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, bufferList, 0, static_cast(matPropsDataSize) ); matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + MATERIAL_DESC_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp new file mode 100644 index 00000000..c2b7c042 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp @@ -0,0 +1,17 @@ +#include "SHpch.h" +#include "SHDescriptorMappings.h" + +namespace SHADE +{ + void SHDescriptorMappings::AddMappings(std::initializer_list> inMappings) noexcept + { + for (auto& map : inMappings) + mappings.emplace(map); + } + + SHDescriptorMappings::MapType const& SHDescriptorMappings::GetMappings(void) const noexcept + { + return mappings; + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h new file mode 100644 index 00000000..67480e7e --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" + +namespace SHADE +{ + class SHDescriptorMappings + { + public: + using MapType = std::unordered_map; + + private: + //! To map an enum value from descriptor set types to set indices + MapType mappings; + + public: + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + void AddMappings (std::initializer_list> inMappings) noexcept; + + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + MapType const& GetMappings (void) const noexcept; + }; + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp new file mode 100644 index 00000000..2d6cc9e1 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp @@ -0,0 +1,30 @@ +#include "SHpch.h" +#include "SHGlobalDescriptorSets.h" + +namespace SHADE +{ + + Handle SHGlobalDescriptorSets::lightDescriptorSet; + + /***************************************************************************/ + /*! + + \brief + Sets the Handle to descriptor set for lights. + + \param lightDescSet + The handle to set to. + + */ + /***************************************************************************/ + void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle lightDescSet) noexcept + { + lightDescriptorSet = lightDescSet; + } + + Handle SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept + { + return lightDescriptorSet; + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h new file mode 100644 index 00000000..ce6c42bb --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" +#include "Resource/SHHandle.h" + +namespace SHADE +{ + // This class is mainly for descriptors that are truly global, meaning they only come from 1 place and they are shared between many systems + class SHGlobalDescriptorSets + { + private: + //! Light data descriptor set + static Handle lightDescriptorSet; + + public: + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + static void SetLightDescriptorSet (Handle lightDescSet) noexcept; + + static Handle GetLightDescriptorSet (void) noexcept; + + }; +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp index d93e073b..ac7fac17 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp @@ -13,7 +13,41 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ std::vector> SHPredefinedData::predefinedLayouts; SHVertexInputState SHPredefinedData::defaultVertexInputState; - Handle SHPredefinedData::dummyPipelineLayout; + SHPredefinedData::PerSystem SHPredefinedData::batchingSystemData; + SHPredefinedData::PerSystem SHPredefinedData::textSystemData; + SHPredefinedData::PerSystem SHPredefinedData::renderGraphNodeComputeData; + + void SHPredefinedData::InitDescMappings(void) noexcept + { + batchingSystemData.descMappings.AddMappings + ({ + {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, + {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1}, + {SHGraphicsConstants::DescriptorSetTypes::MATERIALS, 2}, + }); + + textSystemData.descMappings.AddMappings + ({ + {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, + {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1}, + {SHGraphicsConstants::DescriptorSetTypes::FONT, 2}, + }); + + renderGraphNodeComputeData.descMappings.AddMappings + ({ + {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, + {SHGraphicsConstants::DescriptorSetTypes::LIGHTS, 1}, + {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 2}, + {SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE, 3}, + {SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE, 4}, + }); + } + + void SHPredefinedData::InitDummyPipelineLayouts(Handle logicalDevice) noexcept + { + batchingSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ batchingSystemData.descSetLayouts }); + textSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ textSystemData.descSetLayouts }); + } /*-----------------------------------------------------------------------------------*/ /* Function Definitions */ @@ -91,35 +125,46 @@ namespace SHADE Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); - // font bitmap data (texture) - SHVkDescriptorSetLayout::Binding fontBitmapBinding - { - .Type = vk::DescriptorType::eCombinedImageSampler, - .Stage = vk::ShaderStageFlagBits::eFragment, - .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, - .DescriptorCount = 1, - }; + //// font bitmap data (texture) + //SHVkDescriptorSetLayout::Binding fontBitmapBinding + //{ + // .Type = vk::DescriptorType::eCombinedImageSampler, + // .Stage = vk::ShaderStageFlagBits::eFragment, + // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, + // .DescriptorCount = 1, + //}; - // font data in the form of matrices - SHVkDescriptorSetLayout::Binding fontMatrixBinding - { - .Type = vk::DescriptorType::eStorageBuffer, - .Stage = vk::ShaderStageFlagBits::eVertex, - .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, - .DescriptorCount = 1, - }; + //// font data in the form of matrices + //SHVkDescriptorSetLayout::Binding fontMatrixBinding + //{ + // .Type = vk::DescriptorType::eStorageBuffer, + // .Stage = vk::ShaderStageFlagBits::eVertex, + // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, + // .DescriptorCount = 1, + //}; - Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); - SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); + //Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); + //SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); predefinedLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(lightDataDescSetLayout); predefinedLayouts.push_back(cameraDataGlobalLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout); - predefinedLayouts.push_back(fontDataDescSetLayout); + //predefinedLayouts.push_back(fontDataDescSetLayout); - dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{predefinedLayouts}); + batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts + ( + SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS + ); + + textSystemData.descSetLayouts = GetPredefinedDescSetLayouts + ( + SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA + ); } void SHPredefinedData::InitDefaultVertexInputState(void) noexcept @@ -136,9 +181,11 @@ namespace SHADE { InitDescSetLayouts(logicalDevice); InitDefaultVertexInputState(); + InitDescMappings(); + InitDummyPipelineLayouts (logicalDevice); } - std::vector> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept + std::vector> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept { std::vector> layoutsFound; for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i) @@ -156,9 +203,20 @@ namespace SHADE return defaultVertexInputState; } - Handle SHPredefinedData::GetDummyPipelineLayout(void) noexcept + + SHPredefinedData::PerSystem const& SHPredefinedData::GetBatchingSystemData(void) noexcept { - return dummyPipelineLayout; + return batchingSystemData; + } + + SHPredefinedData::PerSystem const& SHPredefinedData::GetTextSystemData(void) noexcept + { + return textSystemData; + } + + SHPredefinedData::PerSystem const& SHPredefinedData::GetRenderGraphNodeComputeData(void) noexcept + { + return renderGraphNodeComputeData; } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h index 5f13a100..b19a1e0b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h @@ -3,6 +3,7 @@ #include "SH_API.h" #include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h" #include "Tools/Utilities/SHUtilities.h" namespace SHADE @@ -12,8 +13,22 @@ namespace SHADE class SHVkDescriptorSetGroup; class SHVkPipelineLayout; + class SH_API SHPredefinedData { + public: + struct PerSystem + { + //! vector of descriptor set layouts used by a system + std::vector> descSetLayouts; + + //! pipeline layout used for binding descriptor sets in the system + static Handle dummyPipelineLayout; + + //! Descriptor type mappings for the system + SHDescriptorMappings descMappings; + }; + private: //! Global descriptor set layouts. Used to allocate descriptor sets static std::vector> predefinedLayouts; @@ -21,10 +36,17 @@ namespace SHADE //! Default vertex input state (used by everything). static SHVertexInputState defaultVertexInputState; - //! Since we want to bind global data but can't do so without a pipeline layout, - //! we create a dummy pipeline layout to use it for binding. - static Handle dummyPipelineLayout; + //! predefined data for the batching system + static PerSystem batchingSystemData; + //! predefined data for the text system + static PerSystem textSystemData; + + //! predefined data for the render graph node computes + static PerSystem renderGraphNodeComputeData; + + static void InitDescMappings (void) noexcept; + static void InitDummyPipelineLayouts (Handle logicalDevice) noexcept; static void InitDescSetLayouts (Handle logicalDevice) noexcept; static void InitDefaultVertexInputState (void) noexcept; @@ -42,8 +64,10 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; - static SHVertexInputState const& GetDefaultViState (void) noexcept; - static Handle GetDummyPipelineLayout (void) noexcept; + static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; + static SHVertexInputState const& GetDefaultViState (void) noexcept; + static PerSystem const& GetBatchingSystemData(void) noexcept; + static PerSystem const& GetTextSystemData(void) noexcept; + static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index e0b76555..c80b9de5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -27,13 +27,28 @@ namespace SHADE public: static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64; - enum class SHPredefinedDescSetLayoutTypes : uint64_t + // This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData + enum class PredefinedDescSetLayoutTypes : uint64_t { STATIC_DATA = 0x01, LIGHTS = 0x02, CAMERA = 0x04, MATERIALS = 0x08, - FONT = 0x10, + }; + + // This enum is different from the one above in that it is used to initialize a hash table to + // with the values here as keys and set indices as values. It is worth noting that some values here + // are not in the above table. This is because those values don't have predefined descriptor set layouts. + // Their layouts and set indices are instead created through introspection in the pipeline layout. + enum class DescriptorSetTypes + { + STATIC_DATA, + LIGHTS, + CAMERA, + MATERIALS, + FONT, + RENDER_GRAPH_RESOURCE, + RENDER_GRAPH_NODE_COMPUTE_RESOURCE, }; struct RenderGraphIndices @@ -42,68 +57,68 @@ namespace SHADE static constexpr uint32_t EDITOR = 0; }; - //struct DescriptorSetIndex - //{ - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for static global values like generic data, and - // texture samplers - // */ - // /***************************************************************************/ - // static constexpr uint32_t STATIC_GLOBALS = 0; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for dynamic global values like lights. - // */ - // /***************************************************************************/ - // static constexpr uint32_t DYNAMIC_GLOBALS = 1; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for high frequency changing global values like - // camera matrices. - // */ - // /***************************************************************************/ - // static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for per-instance/material changing values. - // */ - // /***************************************************************************/ - // static constexpr uint32_t PER_INSTANCE = 3; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for render graph resources. Unlike the sets from - // 1 to 3 and 6, this set index does not have hard coded bindings and is - // NOT part of the layouts included in the global data. - // */ - // /***************************************************************************/ - // static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; - // /***************************************************************************/ - // /*! - // \brief - // DescriptorSet Index for render graph node compute resources. For data - // that we wish to pass to compute shaders in the render graph, this is - // the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have - // hard coded bindings and is NOT part of the layouts included in the global - // data. - // */ - // /***************************************************************************/ - // static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; + struct DescriptorSetIndex + { + /***************************************************************************/ + /*! + \brief + DescriptorSet Index for static global values like generic data, and + texture samplers + */ + /***************************************************************************/ + static constexpr uint32_t STATIC_GLOBALS = 0; + /***************************************************************************/ + /*! + \brief + DescriptorSet Index for dynamic global values like lights. + */ + /***************************************************************************/ + static constexpr uint32_t DYNAMIC_GLOBALS = 1; + /***************************************************************************/ + /*! + \brief + DescriptorSet Index for high frequency changing global values like + camera matrices. + */ + /***************************************************************************/ + static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; + /***************************************************************************/ + /*! + \brief + DescriptorSet Index for per-instance/material changing values. + */ + /***************************************************************************/ + static constexpr uint32_t PER_INSTANCE = 3; + /***************************************************************************/ + /*! + \brief + DescriptorSet Index for render graph resources. Unlike the sets from + 1 to 3 and 6, this set index does not have hard coded bindings and is + NOT part of the layouts included in the global data. + */ + /***************************************************************************/ + static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; + /***************************************************************************/ + /*! + \brief + DescriptorSet Index for render graph node compute resources. For data + that we wish to pass to compute shaders in the render graph, this is + the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have + hard coded bindings and is NOT part of the layouts included in the global + data. + */ + /***************************************************************************/ + static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; - // /***************************************************************************/ - // /*! - // \brief - // To store font data. - // - // */ - // /***************************************************************************/ - // static constexpr uint32_t FONT_DATA = 4; - //}; + /***************************************************************************/ + /*! + \brief + To store font data. + + */ + /***************************************************************************/ + static constexpr uint32_t FONT_DATA = 4; + }; struct DescriptorSetBindings { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index c9e7f2d2..6881d7a8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -903,7 +903,7 @@ namespace SHADE void SHGraphicsSystem::BuildFonts(void) noexcept { - fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::FONT)[0], resourceManager); + fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); } #pragma endregion ADD_REMOVE @@ -1137,7 +1137,7 @@ namespace SHADE device, SHPipelineLayoutParams { .shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader }, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::CAMERA) + .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA) } ); auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 9e6f1bd7..9b16a279 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -13,7 +13,7 @@ namespace SHADE SHPipelineLayoutParams params { .shaderModules = {vsFsPair.first, vsFsPair.second}, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts() + .globalDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts }; // Create the pipeline layout diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index f0e375e6..f117b26c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -103,7 +103,7 @@ namespace SHADE SHPipelineLayoutParams plParams { .shaderModules = {textVS, textFS}, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts() + .predefinedDescSetLayouts = SHPredefinedData::GetTextSystemData().descSetLayouts }; pipelineLayout = logicalDevice->CreatePipelineLayout(plParams); diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h index 010bed0e..3288d196 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h @@ -25,7 +25,7 @@ namespace SHADE //! used just for textures or lights for example). In that case, we still //! want to use the layout to initialize the pipeline layout but we do not //! want to use it for allocating descriptor sets. - std::vector> const& globalDescSetLayouts = {}; + std::vector> const& predefinedDescSetLayouts = {}; //! Since both SPIRV-Reflect and GLSL don't provide ways to describe UBOs or //! SSBOs as dynamic, we need to do it ourselves. This will store bindings diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index aca987d8..ea574158 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -27,7 +27,7 @@ namespace SHADE SHPipelineLayoutParams pipelineLayoutParams { .shaderModules = {computeShaderModule}, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(), + .predefinedDescSetLayouts = SHPredefinedData::GetRenderGraphNodeComputeData().descSetLayouts, .dynamicBufferBindings = std::move(dynamicBufferBindings), }; @@ -45,10 +45,13 @@ namespace SHADE // save the resources resources = std::move (subpassComputeResources); + auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; + auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline(); - //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]; + + //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 = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE)]; // Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE) for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) @@ -60,14 +63,12 @@ namespace SHADE #endif } - - auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline(); - - if (layouts.size() == SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE + 1) + // check if all layouts are there + if (layouts.size() == descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) { // create compute resources computeResource = graphStorage->resourceHub->Create(); - auto computeResourceLayout = layouts[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE]; + auto computeResourceLayout = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 }); #ifdef _DEBUG for (auto set : computeResource->descSet->GetVkHandle()) @@ -91,12 +92,14 @@ namespace SHADE // bind the compute pipeline cmdBuffer->BindPipeline(computePipeline); + auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; + // bind descriptor sets - cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, {}); + cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {}); if (computeResource) { - cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, computeResource->dynamicOffsets[frameIndex]); + cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]); } // dispatch compute @@ -109,8 +112,11 @@ namespace SHADE void SHRenderGraphNodeCompute::HandleResize(void) noexcept { + auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; + uint32_t renderGraphResourceSetIndex = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE); + // Get the layout for the render graph resource. We can index it this way because the container returned is a container of layouts that includes the global ones - auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE]; + auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[renderGraphResourceSetIndex]; // everything below here needs resizing for (uint32_t frameIndex = 0; frameIndex < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++frameIndex) @@ -123,8 +129,8 @@ namespace SHADE uint32_t imageIndex = (resources[i]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0; SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle{}, vk::ImageLayout::eGeneral); - graphResourceDescSets[frameIndex]->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint, { &vsl, 1 }); - graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint); + graphResourceDescSets[frameIndex]->ModifyWriteDescImage(renderGraphResourceSetIndex, binding.BindPoint, { &vsl, 1 }); + graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(renderGraphResourceSetIndex, binding.BindPoint); ++i; } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp index b8717925..4c575c99 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp @@ -24,7 +24,7 @@ namespace SHADE auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams { .shaderModules = {shaderModules.first, shaderModules.second}, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(), + .predefinedDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts }); pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); From 44ca317e1da5eba19d778d1c4ca704a76af14e99 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 28 Dec 2022 10:22:01 +0800 Subject: [PATCH 10/24] WIP will update later, afraid for BSOD again --- Assets/Shaders/DebugDrawMesh_VS.glsl | 3 +- Assets/Shaders/DebugDraw_VS.glsl | 3 +- Assets/Shaders/TestCube_Tile_VS.glsl | 3 +- Assets/Shaders/TestCube_VS.glsl | 3 +- Assets/Shaders/Text_VS.glsl | 5 +- Assets/Shaders/UI_VS.glsl | 5 +- SHADE_Engine/src/Editor/SHEditor.cpp | 7 +- .../Graphics/Commands/SHVkCommandBuffer.cpp | 2 +- .../src/Graphics/Commands/SHVkCommandBuffer.h | 2 +- .../GlobalData/SHGlobalDescriptorSets.cpp | 31 +- .../GlobalData/SHGlobalDescriptorSets.h | 24 +- .../MiddleEnd/GlobalData/SHPredefinedData.cpp | 41 +- .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 8 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 1 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 359 ++++++++++++------ .../MiddleEnd/Interface/SHGraphicsSystem.h | 30 +- .../MiddleEnd/Interface/SHRenderer.cpp | 89 ++--- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 34 +- .../MiddleEnd/Interface/SHViewport.cpp | 28 -- .../Graphics/MiddleEnd/Interface/SHViewport.h | 14 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 11 +- .../MiddleEnd/Lights/SHLightingSubSystem.h | 11 +- .../SHTextRenderingSubSystem.cpp | 30 +- .../TextRendering/SHTextRenderingSubSystem.h | 8 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 53 ++- .../src/Graphics/RenderGraph/SHRenderGraph.h | 16 +- .../RenderGraph/SHRenderGraphNode.cpp | 14 +- .../Graphics/RenderGraph/SHRenderGraphNode.h | 6 +- .../RenderGraph/SHRenderGraphNodeCompute.h | 2 + .../src/Graphics/RenderGraph/SHSubpass.cpp | 34 +- .../src/Graphics/RenderGraph/SHSubpass.h | 24 +- 31 files changed, 548 insertions(+), 353 deletions(-) diff --git a/Assets/Shaders/DebugDrawMesh_VS.glsl b/Assets/Shaders/DebugDrawMesh_VS.glsl index 2f035261..19c1a5b9 100644 --- a/Assets/Shaders/DebugDrawMesh_VS.glsl +++ b/Assets/Shaders/DebugDrawMesh_VS.glsl @@ -16,8 +16,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() diff --git a/Assets/Shaders/DebugDraw_VS.glsl b/Assets/Shaders/DebugDraw_VS.glsl index 42a48c01..ce2dd544 100644 --- a/Assets/Shaders/DebugDraw_VS.glsl +++ b/Assets/Shaders/DebugDraw_VS.glsl @@ -15,8 +15,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() diff --git a/Assets/Shaders/TestCube_Tile_VS.glsl b/Assets/Shaders/TestCube_Tile_VS.glsl index 31a448fe..d27805ef 100644 --- a/Assets/Shaders/TestCube_Tile_VS.glsl +++ b/Assets/Shaders/TestCube_Tile_VS.glsl @@ -39,8 +39,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials diff --git a/Assets/Shaders/TestCube_VS.glsl b/Assets/Shaders/TestCube_VS.glsl index 774bc580..0e055395 100644 --- a/Assets/Shaders/TestCube_VS.glsl +++ b/Assets/Shaders/TestCube_VS.glsl @@ -34,8 +34,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index 3501a13d..0498ae39 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -30,8 +30,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; // push constants @@ -96,6 +95,6 @@ void main() Out2.textColor = testPushConstant.textColor; // transform the vertex position to font space - gl_Position = cameraData.orthoMat * localModel * vec4(vertexPos, 1.0f); + gl_Position = cameraData.projMat * localModel * vec4(vertexPos, 1.0f); // gl_Position = vec4(vertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/UI_VS.glsl b/Assets/Shaders/UI_VS.glsl index c4393b98..622cf827 100644 --- a/Assets/Shaders/UI_VS.glsl +++ b/Assets/Shaders/UI_VS.glsl @@ -34,8 +34,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() @@ -60,7 +59,7 @@ void main() Out.normal.rgb = normalize (Out.normal.rgb); // clip space for rendering - gl_Position = cameraData.orthoMat * worldTransform * vec4 (aVertexPos, 1.0f); + gl_Position = cameraData.projMat * worldTransform * vec4 (aVertexPos, 1.0f); gl_Position.z += 0.1f; // HAX // gl_Position = vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index 4f1586ac..a12a19f7 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -500,10 +500,7 @@ namespace SHADE imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); //auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers(); - auto const& renderers = gfxSystem->GetEditorViewport()->GetRenderers(); - - SHASSERT(!renderers.empty(), "No Renderers available") - auto renderGraph = renderers[SHGraphicsConstants::RenderGraphIndices::EDITOR]->GetRenderGraph(); + auto renderGraph = gfxSystem->GetRenderGraph(); auto renderPass = renderGraph->GetNode("ImGui Node")->GetRenderpass(); if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false) @@ -523,7 +520,7 @@ namespace SHADE ImGui_ImplVulkan_DestroyFontUploadObjects(); - renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle& cmd, uint32_t frameIndex) + renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) { cmd->BeginLabeledSegment("ImGui Draw"); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp index 05fd4288..37b89883 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp @@ -367,7 +367,7 @@ namespace SHADE } } - void SHVkCommandBuffer::BindDescriptorSet(Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span dynamicOffsets) + void SHVkCommandBuffer::BindDescriptorSet(Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span const dynamicOffsets) { uint32_t bindPointIndex = static_cast(bindPoint); vkCommandBuffer.bindDescriptorSets(SHVkUtil::GetPipelineBindPointFromType(bindPoint), bindPointData[bindPointIndex].boundPipelineLayoutHdl->GetVkPipelineLayout(), firstSet, descSetGroup->GetVkHandle(), dynamicOffsets); diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h index fc348487..c6a17d2a 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h @@ -125,7 +125,7 @@ namespace SHADE void BindPipeline (Handle const& pipelineHdl) noexcept; void BindVertexBuffer (uint32_t bindingPoint, Handle const& buffer, vk::DeviceSize offset) noexcept; void BindIndexBuffer (Handle const& buffer, uint32_t startingIndex) const noexcept; - void BindDescriptorSet (Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span dynamicOffsets); + void BindDescriptorSet (Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span const dynamicOffsets); // Draw Commands void DrawArrays (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) const noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp index 2d6cc9e1..09dbef51 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp @@ -1,10 +1,31 @@ #include "SHpch.h" #include "SHGlobalDescriptorSets.h" +#include "Graphics/MiddleEnd/Lights/SHLightingSubSystem.h" +#include "Graphics/Commands/SHVkCommandBuffer.h" namespace SHADE { - Handle SHGlobalDescriptorSets::lightDescriptorSet; + Handle SHGlobalDescriptorSets::staticGlobalDataDescriptorSet; + Handle SHGlobalDescriptorSets::lightingSubSystem; + + //void SHGlobalDescriptorSets::BindLightingData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t firstSet) noexcept + //{ + // // Bind descriptor set for light data + // cmdBuffer->BindDescriptorSet(SHGlobalDescriptorSets::GetLightDescriptorSet(), SH_PIPELINE_TYPE::COMPUTE, descMappings[SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS], const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); + //} + + void SHGlobalDescriptorSets::BindLightingData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept + { + lightingSubSystem->BindDescSet(cmdBuffer, setIndex, frameIndex); + } + + void SHGlobalDescriptorSets::BindStaticGlobalData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept + { + // Bind descriptor set for static global data + static constexpr std::array TEX_DYNAMIC_OFFSET{ 0 }; + cmdBuffer->BindDescriptorSet(staticGlobalDataDescriptorSet, pipelineType, setIndex, const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); + } /***************************************************************************/ /*! @@ -17,14 +38,14 @@ namespace SHADE */ /***************************************************************************/ - void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle lightDescSet) noexcept + void SHGlobalDescriptorSets::SetLightingSubSystem(Handle system) noexcept { - lightDescriptorSet = lightDescSet; + lightingSubSystem = system; } - Handle SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept + void SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(Handle staticGlobalDescSet) noexcept { - return lightDescriptorSet; + staticGlobalDataDescriptorSet = staticGlobalDescSet; } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h index ce6c42bb..2e2dca7d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h @@ -2,23 +2,35 @@ #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Resource/SHHandle.h" +#include "Graphics/Pipeline/SHPipelineType.h" namespace SHADE { + class SHLightingSubSystem; + class SHVkCommandBuffer; + // This class is mainly for descriptors that are truly global, meaning they only come from 1 place and they are shared between many systems class SHGlobalDescriptorSets { private: - //! Light data descriptor set - static Handle lightDescriptorSet; + + //! Static global descriptor sets for miscellaneous data and textures + static Handle staticGlobalDataDescriptorSet; + //! Lighting sub system required to get information to bind descriptor sets for light data + static Handle lightingSubSystem; + public: + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + static void BindLightingData (Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept; + static void BindStaticGlobalData (Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept; + /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static void SetLightDescriptorSet (Handle lightDescSet) noexcept; - - static Handle GetLightDescriptorSet (void) noexcept; - + static void SetLightingSubSystem (Handle system) noexcept; + static void SetStaticGlobalDataDescriptorSet (Handle staticGlobalDescSet) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp index ac7fac17..ac7ab982 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp @@ -125,33 +125,33 @@ namespace SHADE Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); - //// font bitmap data (texture) - //SHVkDescriptorSetLayout::Binding fontBitmapBinding - //{ - // .Type = vk::DescriptorType::eCombinedImageSampler, - // .Stage = vk::ShaderStageFlagBits::eFragment, - // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, - // .DescriptorCount = 1, - //}; + // font bitmap data (texture) + SHVkDescriptorSetLayout::Binding fontBitmapBinding + { + .Type = vk::DescriptorType::eCombinedImageSampler, + .Stage = vk::ShaderStageFlagBits::eFragment, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, + .DescriptorCount = 1, + }; - //// font data in the form of matrices - //SHVkDescriptorSetLayout::Binding fontMatrixBinding - //{ - // .Type = vk::DescriptorType::eStorageBuffer, - // .Stage = vk::ShaderStageFlagBits::eVertex, - // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, - // .DescriptorCount = 1, - //}; + // font data in the form of matrices + SHVkDescriptorSetLayout::Binding fontMatrixBinding + { + .Type = vk::DescriptorType::eStorageBuffer, + .Stage = vk::ShaderStageFlagBits::eVertex, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, + .DescriptorCount = 1, + }; - //Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); - //SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); + Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); + SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); predefinedLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(lightDataDescSetLayout); predefinedLayouts.push_back(cameraDataGlobalLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout); - //predefinedLayouts.push_back(fontDataDescSetLayout); + predefinedLayouts.push_back(fontDataDescSetLayout); batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts ( @@ -163,7 +163,8 @@ namespace SHADE textSystemData.descSetLayouts = GetPredefinedDescSetLayouts ( SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA + SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index d77fbeb0..b57249de 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -99,10 +99,10 @@ namespace SHADE createMeshBatches(); // Register function for subpass - auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); - auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph(); + //auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); + auto renderGraph = gfxSystem->GetRenderGraph(); auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw"); - subPass->AddExteriorDrawCalls([this](Handle& cmdBuffer, uint32_t frameIndex) + subPass->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); cmdBuffer->BeginLabeledSegment("SHDebugDraw (No Depth Test)"); @@ -126,7 +126,7 @@ namespace SHADE cmdBuffer->EndLabeledSegment(); }); auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth"); - subPassWithDepth->AddExteriorDrawCalls([this](Handle& cmdBuffer, uint32_t frameIndex) + subPassWithDepth->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); cmdBuffer->BeginLabeledSegment("SHDebugDraw (Depth Tested)"); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index c80b9de5..06ffe381 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -34,6 +34,7 @@ namespace SHADE LIGHTS = 0x02, CAMERA = 0x04, MATERIALS = 0x08, + FONT = 0x10, }; // This enum is different from the one above in that it is used to initialize a hash table to diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6881d7a8..461b8783 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -44,6 +44,7 @@ of DigiPen Institute of Technology is prohibited. #include "../Meshes/SHPrimitiveGenerator.h" #include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" namespace SHADE { @@ -142,7 +143,7 @@ namespace SHADE static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); } - void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept + void SHGraphicsSystem::InitRenderGraph(void) noexcept { /*-----------------------------------------------------------------------*/ /* MIDDLE END SETUP @@ -158,55 +159,66 @@ namespace SHADE auto cameraSystem = SHSystemManager::GetSystem(); // Set Up Cameras - screenCamera = resourceManager.Create(); - screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); - screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); + //screenCamera = resourceManager.Create(); + //screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); + //screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); - worldCamera = resourceManager.Create(); - 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(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); + //worldCamera = resourceManager.Create(); + //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(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); worldCameraDirector = cameraSystem->CreateDirector(); + /*-----------------------------------------------------------------------*/ + /* PREPARE RENDERERS */ + /*-----------------------------------------------------------------------*/ + // Add world renderer to default viewport + worldRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE); + worldRenderer->SetCameraDirector(worldCameraDirector); + + // Add screen renderer to default viewport + screenRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); + screenRenderer->SetCameraDirector(worldCameraDirector); + // Create Default Viewport worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(window->GetWindowSize().first), static_cast(window->GetWindowSize().second), 0.0f, 1.0f)); - // Get render graph from default viewport world renderer - worldRenderGraph = resourceManager.Create(); - std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) { renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; } + // Get render graph from default viewport world renderer + renderGraph = resourceManager.Create(); + /*-----------------------------------------------------------------------*/ /* WORLD RENDER GRAPH RESOURCES */ /*-----------------------------------------------------------------------*/ // Initialize world render graph - worldRenderGraph->Init("World Render Graph", device, swapchain, &resourceManager); - worldRenderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - worldRenderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); + renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); //worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - worldRenderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); - 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, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, 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, 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); + renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); + renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + renderGraph->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); + renderGraph->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); + renderGraph->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); + renderGraph->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); + renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second, vk::Format::eR8Unorm); /*-----------------------------------------------------------------------*/ /* MAIN NODE */ /*-----------------------------------------------------------------------*/ - auto gBufferNode = worldRenderGraph->AddNode("G-Buffer", + auto gBufferNode = renderGraph->AddNode("G-Buffer", { "Position", "Entity ID", "Light Layer Indices", "Normals", - //"Tangents", "Albedo", "Depth Buffer", "Scene", @@ -218,20 +230,21 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* G-BUFFER SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write"); + auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write", worldViewport, worldRenderer); gBufferSubpass->AddColorOutput("Position"); gBufferSubpass->AddColorOutput("Entity ID"); gBufferSubpass->AddColorOutput("Light Layer Indices"); gBufferSubpass->AddColorOutput("Normals"); - //gBufferSubpass->AddColorOutput("Tangents"); gBufferSubpass->AddColorOutput("Albedo"); gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); + /*-----------------------------------------------------------------------*/ /* SSAO PASS AND DATA INIT */ /*-----------------------------------------------------------------------*/ ssaoStorage = resourceManager.Create(); + // command buffer operation to transfer data for ssao ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); SET_VK_OBJ_NAME(device, vk::ObjectType::eCommandBuffer, ssaoTransferCmdBuffer->GetVkCommandBuffer(), "[Command Buffer] SSAO Pass (Graphics)"); ssaoTransferCmdBuffer->BeginRecording(); @@ -240,50 +253,80 @@ namespace SHADE ssaoTransferCmdBuffer->EndRecording(); graphicsQueue->SubmitCommandBuffer({ ssaoTransferCmdBuffer }); - // Set up Debug Draw Passes - // - Depth Tested - auto debugDrawNodeDepth = worldRenderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"}); - auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth"); - debugDrawDepthSubpass->AddColorOutput("Scene"); - debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); - // - No Depth Test - auto debugDrawNode = worldRenderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" }); - auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw"); - debugDrawSubpass->AddColorOutput("Scene"); + // wait for command buffer to finish executing graphicsQueue->WaitIdle(); - ssaoStorage->PrepareRotationVectorsVkData(device); + // Add the pass to generate an image with just SSAO data Handle ssaoPass = gBufferNode->AddNodeCompute("SSAO", ssaoShader, { "Position", "Normals", "SSAO" }); auto ssaoDataBuffer = ssaoStorage->GetBuffer(); ssaoPass->ModifyWriteDescBufferComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_BUFFER_BINDING, { &ssaoDataBuffer, 1 }, 0, ssaoStorage->GetBuffer()->GetSizeStored()); auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout(); - ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, {&viewSamplerLayout, 1}); + ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 }); - - Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, {"SSAO", "SSAO Blur"}); + // Add another pass to blur SSAO + Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" }); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"}); + gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); + + /*-----------------------------------------------------------------------*/ + /* DEBUG DRAW PASS INIT */ + /*-----------------------------------------------------------------------*/ + // Set up Debug Draw Passes + // - Depth Tested + auto debugDrawNodeDepth = renderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"}); + auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer); + debugDrawDepthSubpass->AddColorOutput("Scene"); + debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); + // - No Depth Test + auto debugDrawNode = renderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" }); + auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw", worldViewport, worldRenderer); + debugDrawSubpass->AddColorOutput("Scene"); + + /*-----------------------------------------------------------------------*/ + /* SCREEN SPACE PASS */ + /*-----------------------------------------------------------------------*/ + auto screenSpaceNode = renderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID" }, {"G-Buffer", "Debug Draw" }); + auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer); + uiSubpass->AddColorOutput("Scene"); + uiSubpass->AddColorOutput("Entity ID"); + uiSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) + { + textRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex); + }); + + /*-----------------------------------------------------------------------*/ + /* RENDER TO SWAPCHAIN IMAGE FOR PRESENT PASS */ + /*-----------------------------------------------------------------------*/ +#ifdef SHEDITOR { - //// 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 = renderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" }); + auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass", {}, {}); + dummySubpass->AddInput("Scene"); + + auto imGuiNode = renderGraph->AddNode("ImGui Node", { "Present" }, {}); + auto imGuiSubpass = imGuiNode->AddSubpass("ImGui Draw", {}, {}); + imGuiSubpass->AddColorOutput("Present"); } +#else + renderGraph->AddRenderToSwapchainNode("Scene", "Present", { "Screen Space Pass" }, { renderToSwapchainVS, renderToSwapchainFS }); +#endif + /*-----------------------------------------------------------------------*/ - /* GENERATE WORLD RENDER GRAPH */ + /* GENERATE RENDER GRAPH */ /*-----------------------------------------------------------------------*/ - // Generate world render graph - worldRenderGraph->Generate(); - + // Generate render graph + renderGraph->Generate(); +#if 0 /*-----------------------------------------------------------------------*/ /* SCREEN RENDER GRAPH */ /*-----------------------------------------------------------------------*/ @@ -317,18 +360,7 @@ namespace SHADE screenRenderGraph->Generate(); - /*-----------------------------------------------------------------------*/ - /* BIND RENDER GRAPH TO RENDERER */ - /*-----------------------------------------------------------------------*/ - // Add world renderer to default viewport - worldRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[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, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph); - screenRenderer->SetCamera(screenCamera); - screenRenderer->SetCameraDirector(worldCameraDirector); +#endif // Create debug draw pipeline debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, false); @@ -361,10 +393,12 @@ namespace SHADE { SHPredefinedData::Init(device); - InitSceneRenderGraph(); + InitRenderGraph(); -#ifdef SHEDITOR - InitEditorRenderGraph(); +#if 0 + #ifdef SHEDITOR + InitEditorRenderGraph(); + #endif #endif // Create Semaphore @@ -377,7 +411,7 @@ namespace SHADE void SHGraphicsSystem::InitSubsystems(void) noexcept { - mousePickSystem = resourceManager.Create(); + mousePickSubSystem = resourceManager.Create(); std::vector> cmdPools; cmdPools.reserve(swapchain->GetNumImages()); @@ -385,11 +419,11 @@ namespace SHADE cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]); // Mouse picking system for the editor (Will still run with editor disabled) - mousePickSystem->Init(device, cmdPools, worldRenderGraph->GetRenderGraphResource("Entity ID")); + mousePickSubSystem->Init(device, cmdPools, renderGraph->GetRenderGraphResource("Entity ID")); // Register the post offscreen render to the system - postOffscreenRender = resourceManager.Create(); - postOffscreenRender->Init(device, worldRenderGraph->GetRenderGraphResource("Scene"), descPool); + postOffscreenRenderSubSystem = resourceManager.Create(); + postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool); lightingSubSystem = resourceManager.Create(); lightingSubSystem->Init(device, descPool); @@ -397,11 +431,11 @@ namespace SHADE textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer - auto uiNode = screenRenderGraph->GetNode("Screen Space Pass"); - textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS, [=](Handle cmdBuffer, uint32_t frameIndex) - { - screenRenderer->BindDescSet(cmdBuffer, frameIndex); - }); + auto uiNode = renderGraph->GetNode("Screen Space Pass"); + textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); + + SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(texLibrary.GetTextureDescriptorSetGroup()); + SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); } @@ -425,41 +459,42 @@ namespace SHADE defaultMaterial = AddMaterial ( defaultVertShader, defaultFragShader, - worldRenderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") + renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") ); defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } -#ifdef SHEDITOR - void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept - { - auto windowDims = window->GetWindowSize(); +#if 0 + #ifdef SHEDITOR + void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept + { + auto windowDims = window->GetWindowSize(); - // Create Default Viewport - editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 1.0f)); + // Create Default Viewport + editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 1.0f)); - // Get render graph from viewport editor renderer - editorRenderGraph = resourceManager.Create(); + // Get render graph from viewport editor renderer + editorRenderGraph = resourceManager.Create(); - std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; - for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) - renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; + std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; + for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) + renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; - editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager); - editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); + editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager); + editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); - auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {}); - auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); - imguiSubpass->AddColorOutput("Present"); + auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {}); + auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); + imguiSubpass->AddColorOutput("Present"); - // Generate world render graph - editorRenderGraph->Generate(); + // Generate world render graph + editorRenderGraph->Generate(); - // Add world renderer to default viewport - editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph); - editorRenderer->SetCamera(worldCamera); - } + // Add world renderer to default viewport + editorRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE); + } + #endif #endif /*---------------------------------------------------------------------------------*/ @@ -547,6 +582,41 @@ namespace SHADE textRenderingSubSystem->Run(frameIndex); + + for (auto renderer : renderers) + { +#ifdef SHEDITOR + if (renderer == worldRenderer) + { + auto editorSystem = SHSystemManager::GetSystem(); + if (editorSystem->editorState != SHEditor::State::PLAY) + worldRenderer->UpdateDataManual(frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix()); + else + renderer->UpdateData(frameIndex); + } + else + renderer->UpdateData(frameIndex); +#else + renderers[renIndex]->UpdateDataAndBind(frameIndex); +#endif + } + + renderGraph->Begin(frameIndex); + auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); + + // Bind all the buffers required for meshes + for (auto& [buffer, bindingPoint] : MESH_DATA) + { + if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer) + cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0); + else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer) + cmdBuffer->BindIndexBuffer(buffer, 0); + } + + renderGraph->Execute(frameIndex, descPool); + renderGraph->End(frameIndex); + +#if 0 // For every viewport for (int vpIndex = 0; vpIndex < static_cast(viewports.size()); ++vpIndex) { @@ -564,10 +634,10 @@ namespace SHADE // Begin recording the command buffer currentCmdBuffer->BeginRecording(); - // set viewport and scissor - uint32_t w = static_cast(viewports[vpIndex]->GetWidth()); - uint32_t h = static_cast(viewports[vpIndex]->GetHeight()); - currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); + //// set viewport and scissor + //uint32_t w = static_cast(viewports[vpIndex]->GetWidth()); + //uint32_t h = static_cast(viewports[vpIndex]->GetHeight()); + //currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); // Force set the pipeline layout currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); @@ -601,20 +671,20 @@ namespace SHADE // bind camera data //renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -#ifdef SHEDITOR - if (renderers[renIndex] == worldRenderer) - { - auto editorSystem = SHSystemManager::GetSystem(); - if (editorSystem->editorState != SHEditor::State::PLAY) - worldRenderer->UpdateDataAndBind(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix()); - else - renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); - } - else - renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -#else - renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -#endif +//#ifdef SHEDITOR +// if (renderers[renIndex] == worldRenderer) +// { +// auto editorSystem = SHSystemManager::GetSystem(); +// if (editorSystem->editorState != SHEditor::State::PLAY) +// worldRenderer->UpdateDataManual(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix()); +// else +// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); +// } +// else +// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); +//#else +// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); +//#endif // Draw the scene renderers[renIndex]->Draw(frameIndex, descPool); @@ -638,8 +708,10 @@ namespace SHADE semIndex = !semIndex; } } +#endif } + /***************************************************************************/ /*! @@ -677,12 +749,8 @@ namespace SHADE // #BackEndTest: For for the fence initialized by queue submit renderContext.WaitForFence(); - // Finalise all batches - for (auto vp : viewports) - for (auto renderer : vp->GetRenderers()) - { - renderer->GetRenderGraph()->FinaliseBatch(renderContext.GetCurrentFrame(), descPool); - } + // finalize batches for render graph + renderGraph->FinaliseBatch(renderContext.GetCurrentFrame(), descPool); // #BackEndTest: Acquire the next image in the swapchain available renderContext.AcquireNextIamge(); @@ -723,7 +791,7 @@ namespace SHADE const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); auto& currFrameData = renderContext.GetCurrentFrameData(); - mousePickSystem->Run(graphicsQueue, CURR_FRAME_IDX); + mousePickSubSystem->Run(graphicsQueue, CURR_FRAME_IDX); // #BackEndTest: queues an image for presentation if (auto result = graphicsQueue->Present(swapchain, { currFrameData.semRenderFinishHdl }, CURR_FRAME_IDX); result != vk::Result::eSuccess) @@ -763,6 +831,40 @@ namespace SHADE viewports.erase(iter); } + /*---------------------------------------------------------------------------------*/ + /* Renderer Registration Functions */ + /*---------------------------------------------------------------------------------*/ + Handle SHGraphicsSystem::AddRenderer(SHRenderer::PROJECTION_TYPE projectionType) + { + std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; + for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) + { + renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; + } + + // Create the renderer + auto renderer = resourceManager.Create(device, swapchain->GetNumImages(), renderContextCmdPools, descPool); + + // Store + renderers.emplace_back(renderer); + + // Return + return renderer; + } + void SHGraphicsSystem::RemoveRenderer(Handle renderer) + { + auto iter = std::find(renderers.begin(), renderers.end(), renderer); + if (iter == renderers.end()) + { + SHLOG_WARNING("Attempted to remove a Renderer that does not belong to a viewport!"); + return; + } + + // Remove it + iter->Free(); + renderers.erase(iter); + } + Handle SHGraphicsSystem::AddMaterial(Handle vertShader, Handle fragShader, Handle subpass) { // Retrieve pipeline from pipeline storage or create if unavailable @@ -1058,7 +1160,7 @@ namespace SHADE renderContext.HandleResize(); - worldRenderGraph->HandleResize(resizeWidth, resizeHeight); + renderGraph->HandleResize(resizeWidth, resizeHeight); #ifdef SHEDITOR @@ -1067,13 +1169,13 @@ namespace SHADE //editorViewport->SetWidth(windowDims.first); //editorViewport->SetHeight(windowDims.second); - editorRenderGraph->HandleResize(windowDims.first, windowDims.second); + //editorRenderGraph->HandleResize(windowDims.first, windowDims.second); #endif - screenRenderGraph->HandleResize(resizeWidth, resizeHeight); + //screenRenderGraph->HandleResize(resizeWidth, resizeHeight); - mousePickSystem->HandleResize(); - postOffscreenRender->HandleResize(); + mousePickSubSystem->HandleResize(); + postOffscreenRenderSubSystem->HandleResize(); worldViewport->SetWidth(static_cast(resizeWidth)); worldViewport->SetHeight(static_cast(resizeHeight)); @@ -1102,9 +1204,14 @@ namespace SHADE } + Handle SHGraphicsSystem::GetRenderGraph(void) const noexcept + { + return renderGraph; + } + Handle SHGraphicsSystem::GetPrimaryRenderpass() const noexcept { - return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); + return renderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); } Handle SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept @@ -1137,7 +1244,7 @@ namespace SHADE device, SHPipelineLayoutParams { .shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader }, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA) + .predefinedDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA) } ); auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 75b48c9b..0aa83f21 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -34,6 +34,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/PostProcessing/SHSSAO.h" #include "Camera/SHCameraDirector.h" #include "Graphics/MiddleEnd/TextRendering/SHFontLibrary.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" namespace SHADE { @@ -49,7 +50,6 @@ namespace SHADE class SHVkImage; class SHVkFramebuffer; class SHVkCommandBuffer; - class SHRenderer; class SHViewport; class SHCamera; class SHVkShaderModule; @@ -99,7 +99,7 @@ namespace SHADE { private: void InitBoilerplate (void) noexcept; - void InitSceneRenderGraph (void) noexcept; + void InitRenderGraph (void) noexcept; void InitMiddleEnd (void) noexcept; void InitSubsystems (void) noexcept; void InitBuiltInResources (void); @@ -171,6 +171,13 @@ namespace SHADE Handle AddViewport(const vk::Viewport& viewport); void RemoveViewport(Handle viewport); + /*-----------------------------------------------------------------------------*/ + /* Renderers Registration Functions */ + /*-----------------------------------------------------------------------------*/ + Handle AddRenderer(SHRenderer::PROJECTION_TYPE projectionType); + void RemoveRenderer(Handle renderer); + + /*-----------------------------------------------------------------------------*/ /* Material Functions */ /*-----------------------------------------------------------------------------*/ @@ -382,8 +389,9 @@ namespace SHADE #ifdef SHEDITOR Handle GetEditorViewport () const {return editorViewport;}; #endif - Handle GetMousePickSystem(void) const noexcept {return mousePickSystem;}; - Handle GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;}; + Handle GetMousePickSystem(void) const noexcept {return mousePickSubSystem;}; + Handle GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRenderSubSystem;}; + Handle GetRenderGraph (void) const noexcept; Handle GetPrimaryRenderpass() const noexcept; Handle GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept; uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); } @@ -441,10 +449,8 @@ namespace SHADE // Renderers Handle worldRenderer; Handle screenRenderer; + std::vector> renderers; - // Temp Cameras - Handle worldCamera; - Handle screenCamera; DirectorHandle worldCameraDirector; @@ -483,15 +489,15 @@ namespace SHADE std::array, MAX_PRIMITIVE_TYPES> primitiveMeshes; // Render Graphs - Handle worldRenderGraph; - Handle screenRenderGraph; + Handle renderGraph; + //Handle screenRenderGraph; #ifdef SHEDITOR - Handle editorRenderGraph; + //Handle editorRenderGraph; #endif // Sub systems - Handle mousePickSystem; - Handle postOffscreenRender; + Handle mousePickSubSystem; + Handle postOffscreenRenderSubSystem; Handle lightingSubSystem; Handle textRenderingSubSystem; Handle ssaoStorage; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index 1136a2c9..be9f0482 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -14,7 +14,6 @@ of DigiPen Institute of Technology is prohibited. #include "SHRenderer.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "SHViewport.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Framebuffer/SHVkFramebuffer.h" #include "SHMaterial.h" @@ -22,22 +21,22 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Camera/SHCameraDirector.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Constructor/Destructors */ /*-----------------------------------------------------------------------------------*/ - SHRenderer::SHRenderer(Handle logicalDevice, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle viewport, Handle renderGraph) - : viewport { viewport } - , renderGraph { renderGraph } + SHRenderer::SHRenderer(Handle logicalDevice, uint32_t numFrames, Handle descriptorPool, PROJECTION_TYPE type) + : projectionType{type} { - commandBuffers.resize(static_cast(numFrames)); + //commandBuffers.resize(static_cast(numFrames)); - for (uint32_t i = 0; i < commandBuffers.size(); ++i) - commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); + //for (uint32_t i = 0; i < commandBuffers.size(); ++i) + // commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); - cameraDescriptorSet = descriptorPool->Allocate({ cameraDescLayout }, { 1 }); + cameraDescriptorSet = descriptorPool->Allocate(SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA), { 1 }); #ifdef _DEBUG const auto& CAM_DESC_SETS = cameraDescriptorSet->GetVkHandle(); @@ -61,18 +60,6 @@ namespace SHADE SHRenderer::~SHRenderer(void) { - //for (auto& cmdBuffer : commandBuffers) - //{ - // cmdBuffer.Free(); - //} - } - - /*-----------------------------------------------------------------------------------*/ - /* Camera Registration */ - /*-----------------------------------------------------------------------------------*/ - void SHRenderer::SetCamera(Handle _camera) - { - camera = _camera; } void SHRenderer::SetCameraDirector(Handle director) noexcept @@ -80,63 +67,55 @@ namespace SHADE cameraDirector = director; } - /*-----------------------------------------------------------------------------------*/ - /* Drawing Functions */ - /*-----------------------------------------------------------------------------------*/ - void SHRenderer::Draw(uint32_t frameIndex, Handle descPool) noexcept + void SHRenderer::UpdateData(uint32_t frameIndex) noexcept { - renderGraph->Execute(frameIndex, commandBuffers[frameIndex], descPool); - } - - void SHRenderer::UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex) noexcept - { - if (camera && cameraDirector) + if (cameraDirector) { - //UpdateDataAndBind(cmdBuffer, frameIndex, SHMatrix::Transpose(cameraDirector->GetVPMatrix())); - UpdateDataAndBind(cmdBuffer, frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix(), cameraDirector->GetOrthoMatrix()); + switch (projectionType) + { + case PROJECTION_TYPE::DEFAULT: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix()); + break; + case PROJECTION_TYPE::PERSPECTIVE: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetPerspectiveMatrix()); + break; + case PROJECTION_TYPE::ORTHOGRAPHIC: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetOrthoMatrix()); + break; + default: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix()); + break; + } } } - void SHRenderer::UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept + void SHRenderer::UpdateDataManual(uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept { - SetViewProjectionMatrix(viewMatrix, projMatrix, orthoMatrix); + SetViewProjectionMatrix(viewMatrix, projMatrix); - //cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix(); cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex); - BindDescSet(cmdBuffer, frameIndex); + //BindDescSet(cmdBuffer, frameIndex); } - void SHRenderer::BindDescSet(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHRenderer::BindDescriptorSet(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept { std::array dynamicOffsets{ frameIndex * cameraDataAlignedSize }; - cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 }); - cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 }); + cmdBuffer->BindDescriptorSet(cameraDescriptorSet, pipelineType, setIndex, std::span{ dynamicOffsets.data(), 1 }); } - void SHRenderer::UpdateCameraDataToBuffer(void) noexcept + void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept { - } - - void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept - { - //cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix(); cpuCameraData.viewProjectionMatrix = SHMatrix::Transpose(projMatrix * viewMatrix); cpuCameraData.viewMatrix = SHMatrix::Transpose(viewMatrix); cpuCameraData.projectionMatrix = SHMatrix::Transpose(projMatrix); - cpuCameraData.orthoMatrix = SHMatrix::Transpose (orthoMatrix); } - Handle SHRenderer::GetRenderGraph(void) const noexcept - { - return renderGraph; - } - - Handle SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept - { - return commandBuffers[frameIndex]; - } + //Handle SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept + //{ + // return commandBuffers[frameIndex]; + //} Handle SHRenderer::GetCameraDirector(void) const noexcept { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 4bd205be..c93050d7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -32,7 +32,6 @@ namespace SHADE class SHVkFramebuffer; class SHMaterial; class SHVkLogicalDevice; - class SHViewport; class SHVkImageView; class SHVkCommandBuffer; class SHCamera; @@ -48,7 +47,6 @@ namespace SHADE SHMatrix viewProjectionMatrix; SHMatrix viewMatrix; SHMatrix projectionMatrix; - SHMatrix orthoMatrix; }; /*---------------------------------------------------------------------------------*/ @@ -64,35 +62,36 @@ namespace SHADE /***********************************************************************************/ class SHRenderer { - public: + enum class PROJECTION_TYPE + { + DEFAULT, + PERSPECTIVE, + ORTHOGRAPHIC + }; + /*-----------------------------------------------------------------------------*/ /* Constructor/Destructors */ /*-----------------------------------------------------------------------------*/ - SHRenderer(Handle logicalDevice, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle viewport, Handle renderGraph); + SHRenderer(Handle logicalDevice, uint32_t numFrames, Handle descriptorPool, PROJECTION_TYPE type); ~SHRenderer(void); /*-----------------------------------------------------------------------------*/ /* Camera Registration */ /*-----------------------------------------------------------------------------*/ - void SetCamera(Handle _camera); void SetCameraDirector (Handle director) noexcept; /*-----------------------------------------------------------------------------*/ /* Drawing Functions */ /*-----------------------------------------------------------------------------*/ - void Draw(uint32_t frameIndex, Handle descPool) noexcept; - void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex) noexcept; - void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t frameIndex) noexcept; - void UpdateCameraDataToBuffer (void) noexcept; - void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept; + void UpdateData(uint32_t frameIndex) noexcept; + void UpdateDataManual(uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; + void BindDescriptorSet (Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept; + void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; /*-----------------------------------------------------------------------------*/ /* Setters and Getters */ /*-----------------------------------------------------------------------------*/ - Handle GetRenderGraph (void) const noexcept; - Handle GetCommandBuffer(uint32_t frameIndex) const noexcept; Handle GetCameraDirector (void) const noexcept; private: @@ -102,9 +101,6 @@ namespace SHADE //! Vulkan UBOs need to be aligned, this is pad SHShaderCameraData struct uint32_t cameraDataAlignedSize; - Handle viewport; - Handle camera; - Handle renderGraph; Handle cameraDescriptorSet; Handle cameraBuffer; @@ -114,10 +110,10 @@ namespace SHADE // GPU. SHShaderCameraData cpuCameraData; - //! Command buffers for the render graph - std::vector> commandBuffers; - + ////! Command buffers for the render graph + //std::vector> commandBuffers; + PROJECTION_TYPE projectionType; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp index 7bd0049f..078261a5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp @@ -46,34 +46,6 @@ namespace SHADE ); } - /*---------------------------------------------------------------------------------*/ - /* Renderer Registration Functions */ - /*---------------------------------------------------------------------------------*/ - Handle SHViewport::AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph) - { - // Create the renderer - auto renderer = resourceManager.Create(device, numFrames, cmdPools, descriptorPool, cameraDescLayout, GetHandle(), renderGraph); - - // Store - renderers.emplace_back(renderer); - - // Return - return renderer; - } - void SHViewport::RemoveRenderer(Handle renderer) - { - auto iter = std::find(renderers.begin(), renderers.end(), renderer); - if (iter == renderers.end()) - { - SHLOG_WARNING("Attempted to remove a Renderer that does not belong to a viewport!"); - return; - } - - // Remove it - iter->Free(); - renderers.erase(iter); - } - void SHViewport::SetWidth(float w) noexcept { viewport.width = w; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h index 26c0a6bd..60bd6e95 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h @@ -56,11 +56,11 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ void SetUp(Handle commandBuffer); - /*-----------------------------------------------------------------------------*/ - /* Renderers Registration Functions */ - /*-----------------------------------------------------------------------------*/ - Handle AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); - void RemoveRenderer(Handle renderer); + ///*-----------------------------------------------------------------------------*/ + ///* Renderers Registration Functions */ + ///*-----------------------------------------------------------------------------*/ + //Handle AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); + //void RemoveRenderer(Handle renderer); /*-----------------------------------------------------------------------------*/ /* Setters */ @@ -79,7 +79,7 @@ namespace SHADE float GetHeight() const { return viewport.height; } float GetMinDepth() const { return viewport.minDepth; } float GetMaxDepth() const { return viewport.maxDepth; } - std::vector>& GetRenderers() { return renderers; } + //std::vector>& GetRenderers() { return renderers; } private: @@ -88,7 +88,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ Handle device; vk::Viewport viewport; - std::vector> renderers; + //std::vector> renderers; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 448c3bed..abbf88c3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -385,7 +385,7 @@ namespace SHADE std::fill (variableSizes.begin(), variableSizes.end(), 1); // Create the descriptor set - lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes); + lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS) }, variableSizes); #ifdef _DEBUG const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle(); for (int i = 0; i < static_cast(CAM_DESC_SETS.size()); ++i) @@ -517,11 +517,16 @@ namespace SHADE } - void SHLightingSubSystem::BindDescSet(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHLightingSubSystem::BindDescSet(Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept { //Bind descriptor set(We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data). - cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, { dynamicOffsets[frameIndex] }); + cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, setIndex, { dynamicOffsets[frameIndex] }); } + Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept + { + return lightingDataDescSet; + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index ae6caead..fa103136 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -4,6 +4,7 @@ #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec4.h" #include "SHLightData.h" +#include #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" namespace SHADE @@ -57,8 +58,11 @@ namespace SHADE class SH_API SHLightingSubSystem { - private: + public: + using DynamicOffsetArray = std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)>; + + private: class PerTypeData { private: @@ -130,7 +134,7 @@ namespace SHADE std::array(SH_LIGHT_TYPE::NUM_TYPES)> perTypeData; //! Container to store dynamic offsets for binding descriptor sets - std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)> dynamicOffsets; + DynamicOffsetArray dynamicOffsets; //! holds the data that represents how many lights are in the scene std::array(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData; @@ -162,7 +166,8 @@ namespace SHADE void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; void Exit (void) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t frameIndex) noexcept; + void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; + Handle GetLightDataDescriptorSet (void) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index f117b26c..f9afa48f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -11,6 +11,8 @@ #include "Graphics/SHVkUtil.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Math/Transform/SHTransformComponent.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" namespace SHADE { @@ -91,12 +93,10 @@ namespace SHADE } - void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept + void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept { SHComponentManager::CreateComponentSparseSet(); - cameraDescSetBind = bindFunction; - logicalDevice = device; // prepare pipeline layout params @@ -174,9 +174,14 @@ namespace SHADE } } - void SHTextRenderingSubSystem::Render(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHTextRenderingSubSystem::Render(Handle cmdBuffer, Handle renderer, uint32_t frameIndex) noexcept { auto& textRendererComps = SHComponentManager::GetDense(); + auto const& mappings = SHPredefinedData::GetTextSystemData().descMappings; + uint32_t fontSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::FONT); + uint32_t staticGlobalSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA); + uint32_t cameraSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA); + for (auto& comp : textRendererComps) { auto* transform = SHComponentManager::GetComponent(comp.GetEID()); @@ -187,16 +192,19 @@ namespace SHADE // bind the pipeline cmdBuffer->BindPipeline(pipeline); + // Bind global data + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, staticGlobalSetIndex); + + // Bind camera data + renderer->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, cameraSetIndex, frameIndex); + + // bind descriptors for font (matrices) + cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, fontSetIndex, {}); + // bind VBO (position and indices) cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); - // bind camera desc set (again). Necessary because pipeline layout is not compatible. - cameraDescSetBind(cmdBuffer, frameIndex); - - // bind descriptors for font (matrices) - cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, {}); - cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS); cmdBuffer->SetPushConstantVariable("TestPushConstant.eid", comp.GetEID(), SH_PIPELINE_TYPE::GRAPHICS); cmdBuffer->SetPushConstantVariable("TestPushConstant.textColor", SHVec3 (1.0f, 1.0f, 1.0f), SH_PIPELINE_TYPE::GRAPHICS); @@ -206,9 +214,7 @@ namespace SHADE // call draw call cmdBuffer->DrawArrays(4, comp.text.size(), 0, 0); //glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, static_cast(textComp.lastRenderedCharacterIndex) + 1); - } - } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index 78b363d4..c9a89129 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -43,18 +43,14 @@ namespace SHADE //! Descriptor set for font data access in shaders //Handle fontDataDescSetLayout; - //! Super temporary. Global descriptor set needs to be revamped along with - //! entire graphics system. - std::function, uint32_t)> cameraDescSetBind; - private: void RecomputePositions(SHTextRenderableComponent& textComp) noexcept; public: - void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept; + void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept; void Run(uint32_t frameIndex) noexcept; - void Render (Handle cmdBuffer, uint32_t frameIndex) noexcept; + void Render (Handle cmdBuffer, Handle renderer, uint32_t frameIndex) noexcept; void Exit(void) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index fc029161..d431cf47 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -14,6 +14,8 @@ #include "Tools/Utilities/SHUtilities.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" + namespace SHADE { @@ -424,7 +426,7 @@ namespace SHADE */ /***************************************************************************/ - void SHRenderGraph::Init(std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub) noexcept + void SHRenderGraph::Init(std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub, std::vector>& cmdPools) noexcept { //resourceHub = std::make_shared(); @@ -437,6 +439,11 @@ namespace SHADE renderGraphStorage->resourceHub = resourceHub; renderGraphStorage->descriptorPool = logicalDevice->CreateDescriptorPools(); + commandBuffers.resize(static_cast(swapchain->GetNumImages())); + + for (uint32_t i = 0; i < commandBuffers.size(); ++i) + commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); + name = std::move(graphName); } @@ -555,16 +562,22 @@ namespace SHADE if (renderGraphStorage->graphResources->contains(toSwapchainResource) && renderGraphStorage->graphResources->contains(swapchainResource)) { auto newNode = AddNode("Render To Present", { ResourceInstruction (toSwapchainResource.c_str()), ResourceInstruction(swapchainResource.c_str()) }, predecessorNodes); - auto newSubpass = newNode->AddSubpass("Render"); + auto newSubpass = newNode->AddSubpass("Render", {}, {}); newSubpass->AddColorOutput(swapchainResource); newSubpass->AddInput(toSwapchainResource); renderToSwapchainImageSystem = renderGraphStorage->resourceHub->Create (newNode, newSubpass, shaderModules); - newSubpass->AddExteriorDrawCalls([=](Handle& cmdBuffer, uint32_t frameIndex) + newSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline()); - + + // If we are rendering to present image, the width and height will be the dimensions of that image. So we need to set viewport scissor. + auto resource = renderGraphStorage->graphResources->at(swapchainResource); + uint32_t w = static_cast(resource->GetWidth()); + uint32_t h = static_cast(resource->GetHeight()); + cmdBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); + newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex); // draw a quad. @@ -616,14 +629,39 @@ namespace SHADE // TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a // better way to manage these - void SHRenderGraph::Execute(uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept + void SHRenderGraph::Execute(uint32_t frameIndex, Handle descPool) noexcept { + auto cmdBuffer = commandBuffers[frameIndex]; cmdBuffer->BeginLabeledSegment(name); + + // Force bind pipeline layout + cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::GRAPHICS); + cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); + + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + for (auto& node : nodes) + { + // bind static global data + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + node->Execute(cmdBuffer, descPool, frameIndex); + } + cmdBuffer->EndLabeledSegment(); } + void SHRenderGraph::Begin(uint32_t frameIndex) noexcept + { + commandBuffers[frameIndex]->BeginRecording(); + + } + + void SHRenderGraph::End(uint32_t frameIndex) noexcept + { + commandBuffers[frameIndex]->EndRecording(); + } + void SHRenderGraph::FinaliseBatch(uint32_t frameIndex, Handle descPool) { for (auto& node : nodes) @@ -670,4 +708,9 @@ namespace SHADE return {}; } + Handle SHRenderGraph::GetCommandBuffer(uint32_t frameIndex) const noexcept + { + return commandBuffers[frameIndex]; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index f892483f..c69e83b1 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -74,6 +74,9 @@ namespace SHADE //! For rendering onto the swapchain Handle renderToSwapchainImageSystem; + //! Command buffer to issue rendering commands + std::vector> commandBuffers; + public: /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ @@ -86,7 +89,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub) noexcept; + void Init (std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub, std::vector>& cmdPools) noexcept; void AddResource(std::string resourceName, std::initializer_list typeFlags, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageUsageFlagBits usageFlags = {}, vk::ImageCreateFlagBits createFlags = {}); void LinkNonOwningResource (Handle resourceOrigin, std::string resourceName) noexcept; Handle AddNode (std::string nodeName, std::initializer_list resourceInstruction, std::initializer_list predecessorNodes) noexcept; @@ -94,16 +97,19 @@ namespace SHADE void Generate (void) noexcept; void CheckForNodeComputes (void) noexcept; - void Execute (uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept; + void Execute (uint32_t frameIndex, Handle descPool) noexcept; + void Begin (uint32_t frameIndex) noexcept; + void End (uint32_t frameIndex) noexcept; void FinaliseBatch (uint32_t frameIndex, Handle descPool); void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - Handle GetNode (std::string const& nodeName) const noexcept; - std::vector> const& GetNodes (void) const noexcept; - Handle GetRenderGraphResource (std::string const& resourceName) const noexcept; + Handle GetNode (std::string const& nodeName) const noexcept; + std::vector> const& GetNodes (void) const noexcept; + Handle GetRenderGraphResource (std::string const& resourceName) const noexcept; + Handle GetCommandBuffer (uint32_t frameIndex) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 0f9379fe..1d8cea62 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -9,6 +9,8 @@ #include "SHRenderGraphStorage.h" #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "Graphics/SHVkUtil.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" namespace SHADE { @@ -238,7 +240,7 @@ namespace SHADE */ /***************************************************************************/ - Handle SHRenderGraphNode::AddSubpass(std::string subpassName) noexcept + Handle SHRenderGraphNode::AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept { // if subpass already exists, don't add. if (subpassIndexing.contains(subpassName)) @@ -253,6 +255,8 @@ namespace SHADE graphStorage->resourceHub->Create ( subpassName, + viewport, + renderer, graphStorage, GetHandle(), static_cast(subpasses.size()), resourceAttachmentMapping.get() ) @@ -318,7 +322,7 @@ namespace SHADE } // insert them all for a subpass to transition them. This subpass is the last subpass - auto dummySubpass = AddSubpass("dummy"); + auto dummySubpass = AddSubpass("dummy", {}, {}); for (auto& resource : resourcesInvolved) { dummySubpass->AddGeneralInput(resource); @@ -331,7 +335,7 @@ namespace SHADE } } - void SHRenderGraphNode::Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept + void SHRenderGraphNode::Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0; commandBuffer->BeginRenderpass(renderpass, framebuffers[framebufferIndex]); @@ -347,10 +351,14 @@ namespace SHADE commandBuffer->EndRenderpass(); + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; // Execute all subpass computes for (auto& sbCompute : nodeComputes) { + // bind lighting data + SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex); + sbCompute->Execute(commandBuffer, frameIndex); } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 2311ee0c..f7e55d4a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -22,6 +22,8 @@ namespace SHADE class SHPredefinedData; class SHRenderGraphStorage; class SHRenderGraphNodeCompute; + class SHRenderer; + class SHViewport; class SH_API SHRenderGraphNode : public ISelfHandle { @@ -102,12 +104,12 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - Handle AddSubpass(std::string subpassName) noexcept; + Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, float numWorkGroupScale = 1.0f) noexcept; void AddDummySubpassIfNeeded (void) noexcept; // TODO: RemoveSubpass() - void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; + void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; void FinaliseBatch(uint32_t frameIndex, Handle descPool); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 580f018c..a9a6ac68 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -50,6 +50,8 @@ namespace SHADE //! Compute resources Handle computeResource; + //! + //! vector of resources needed by the subpass compute std::vector> resources; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index c1d53632..e5052f59 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -11,6 +11,9 @@ #include "Graphics/Swapchain/SHVkSwapchain.h" #include "Graphics/Images/SHVkSampler.h" #include "SHRenderGraphResource.h" +#include "Graphics/MiddleEnd/Interface/SHViewport.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" namespace SHADE { @@ -30,7 +33,7 @@ namespace SHADE */ /***************************************************************************/ - SHSubpass::SHSubpass(const std::string& name, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept + SHSubpass::SHSubpass(const std::string& name, Handle inViewport, Handle inRenderer, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept : resourceAttachmentMapping{ mapping } , parentNode{ parent } , subpassIndex{ index } @@ -41,6 +44,8 @@ namespace SHADE , name { name } , graphStorage{ renderGraphStorage } , inputImageDescriptorSets{} + , viewport {inViewport} + , renderer {inRenderer} { } @@ -71,6 +76,8 @@ namespace SHADE , inputDescriptorLayout{ rhs.inputDescriptorLayout } , inputSamplers{ rhs.inputSamplers } , name { rhs.name } + , viewport {rhs.viewport} + , renderer {rhs.renderer} { } @@ -106,6 +113,9 @@ namespace SHADE inputDescriptorLayout = rhs.inputDescriptorLayout; inputSamplers = rhs.inputSamplers; name = std::move(rhs.name); + renderer = rhs.renderer; + viewport = rhs.viewport; + return *this; } @@ -199,21 +209,33 @@ namespace SHADE inputReferences.push_back({ resourceAttachmentMapping->at(graphStorage->graphResources->at(resourceToReference).GetId().Raw), vk::ImageLayout::eGeneral }); } - void SHSubpass::Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept + void SHSubpass::Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { commandBuffer->BeginLabeledSegment(name); - // Ensure correct transforms are provided superBatch->UpdateBuffers(frameIndex, descPool); + if (viewport) + { + // set viewport and scissor + uint32_t w = static_cast(viewport->GetWidth()); + uint32_t h = static_cast(viewport->GetHeight()); + commandBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); + } + + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + + if (renderer) + renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + // Draw all the batches superBatch->Draw(commandBuffer, frameIndex); // Draw all the exterior draw calls for (auto& drawCall : exteriorDrawCalls) { - drawCall(commandBuffer, frameIndex); + drawCall(commandBuffer, renderer, frameIndex); } commandBuffer->EndLabeledSegment(); } @@ -231,7 +253,7 @@ namespace SHADE } } - void SHSubpass::AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept + void SHSubpass::AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept { exteriorDrawCalls.push_back(newDrawCall); } @@ -266,7 +288,7 @@ namespace SHADE } // We build a new descriptor set layout to store our images - inputDescriptorLayout = graphStorage->logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, bindings); + inputDescriptorLayout = graphStorage->logicalDevice->CreateDescriptorSetLayout(bindings); // we store a sampler if its an input attachment. if it is storage image, no need sampler, store an empty handle. for (uint32_t i = 0; i < bindings.size(); ++i) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 69b8fd56..b5c5c8b1 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -19,15 +19,28 @@ namespace SHADE class SHRenderGraphStorage; class SHVkShaderModule; class SHVkSampler; + class SHRenderer; + class SHViewport; class SH_API SHSubpass : public ISelfHandle { + public: + using ExteriorDrawCallFunction = std::function, Handle, uint32_t)>; + private: /*---------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ /*---------------------------------------------------------------------*/ Handle graphStorage; + //! Viewport to specify what part of the screen we want to draw on. This + //! will be used in vkCmdSetViewport/Scissor. + Handle viewport; + + //! Renderer used during the subpass execution. This dictates what matrix gets + //! passed to the shaders. + Handle renderer; + //! The index of the subpass in the render graph uint32_t subpassIndex; @@ -79,8 +92,9 @@ namespace SHADE //! after we draw everything from the batch. Because of this, these draw calls //! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING //! COMPLEX. - std::vector&, uint32_t)>> exteriorDrawCalls; - /// For identifying subpasses + std::vector exteriorDrawCalls; + + // For identifying subpasses std::string name; @@ -88,7 +102,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - SHSubpass(const std::string& name, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept; + SHSubpass(const std::string& name, Handle inViewport, Handle inRenderer, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept; SHSubpass(SHSubpass&& rhs) noexcept; SHSubpass& operator=(SHSubpass&& rhs) noexcept; @@ -102,10 +116,10 @@ namespace SHADE void AddGeneralDepthOutput(std::string resourceToReference) noexcept; void AddInput(std::string resourceToReference) noexcept; void AddGeneralInput (std::string resourceToReference) noexcept; - void AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept; + void AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept; // Runtime functions - void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; + void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; void BindDescriptorInputDescriptorSets (Handle cmdBuffer, uint32_t frameIndex) const noexcept; From 3bfec1e54ff0ff5d9a3fd5b75f37e7ca9a976bfe Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 28 Dec 2022 10:22:01 +0800 Subject: [PATCH 11/24] WIP will update later, afraid for BSOD again - All Shaders now take in a single projection matrix. The type of projection matrix is dependent on the SHRenderer projection type. - SHGraphicsSystem now only has a single render graph. - SHGlobalDescriptorSets now store a descriptor set for static global data and a handle to the lighting system. Functions to bind their descriptor sets are also available. - Font desc set layout is added back into SHPredefinedData because while its possible to introspect the layouts from the shaders, the layouts is required beforehand to generate the font objects - SHRenderers and SHViewport are now 2 separate entities, both passable to SHSubpass to be contained and used to set viewport/scissor and send camera matrices to shaders. - SHRenderer descriptor sets are now updated separately from the binding. They happen directly before the render graph executes. --- Assets/Shaders/DebugDrawMesh_VS.glsl | 3 +- Assets/Shaders/DebugDraw_VS.glsl | 3 +- Assets/Shaders/TestCube_Tile_VS.glsl | 3 +- Assets/Shaders/TestCube_VS.glsl | 3 +- Assets/Shaders/Text_VS.glsl | 5 +- Assets/Shaders/UI_VS.glsl | 5 +- SHADE_Engine/src/Editor/SHEditor.cpp | 7 +- .../Graphics/Commands/SHVkCommandBuffer.cpp | 2 +- .../src/Graphics/Commands/SHVkCommandBuffer.h | 2 +- .../GlobalData/SHGlobalDescriptorSets.cpp | 31 +- .../GlobalData/SHGlobalDescriptorSets.h | 24 +- .../MiddleEnd/GlobalData/SHPredefinedData.cpp | 41 +- .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 8 +- .../MiddleEnd/Interface/SHGraphicsConstants.h | 1 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 359 ++++++++++++------ .../MiddleEnd/Interface/SHGraphicsSystem.h | 30 +- .../MiddleEnd/Interface/SHRenderer.cpp | 89 ++--- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 34 +- .../MiddleEnd/Interface/SHViewport.cpp | 28 -- .../Graphics/MiddleEnd/Interface/SHViewport.h | 14 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 11 +- .../MiddleEnd/Lights/SHLightingSubSystem.h | 11 +- .../SHTextRenderingSubSystem.cpp | 30 +- .../TextRendering/SHTextRenderingSubSystem.h | 8 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 53 ++- .../src/Graphics/RenderGraph/SHRenderGraph.h | 16 +- .../RenderGraph/SHRenderGraphNode.cpp | 14 +- .../Graphics/RenderGraph/SHRenderGraphNode.h | 6 +- .../RenderGraph/SHRenderGraphNodeCompute.h | 2 + .../src/Graphics/RenderGraph/SHSubpass.cpp | 34 +- .../src/Graphics/RenderGraph/SHSubpass.h | 24 +- 31 files changed, 548 insertions(+), 353 deletions(-) diff --git a/Assets/Shaders/DebugDrawMesh_VS.glsl b/Assets/Shaders/DebugDrawMesh_VS.glsl index 2f035261..19c1a5b9 100644 --- a/Assets/Shaders/DebugDrawMesh_VS.glsl +++ b/Assets/Shaders/DebugDrawMesh_VS.glsl @@ -16,8 +16,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() diff --git a/Assets/Shaders/DebugDraw_VS.glsl b/Assets/Shaders/DebugDraw_VS.glsl index 42a48c01..ce2dd544 100644 --- a/Assets/Shaders/DebugDraw_VS.glsl +++ b/Assets/Shaders/DebugDraw_VS.glsl @@ -15,8 +15,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() diff --git a/Assets/Shaders/TestCube_Tile_VS.glsl b/Assets/Shaders/TestCube_Tile_VS.glsl index 31a448fe..d27805ef 100644 --- a/Assets/Shaders/TestCube_Tile_VS.glsl +++ b/Assets/Shaders/TestCube_Tile_VS.glsl @@ -39,8 +39,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials diff --git a/Assets/Shaders/TestCube_VS.glsl b/Assets/Shaders/TestCube_VS.glsl index 774bc580..0e055395 100644 --- a/Assets/Shaders/TestCube_VS.glsl +++ b/Assets/Shaders/TestCube_VS.glsl @@ -34,8 +34,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index 3501a13d..0498ae39 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -30,8 +30,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; // push constants @@ -96,6 +95,6 @@ void main() Out2.textColor = testPushConstant.textColor; // transform the vertex position to font space - gl_Position = cameraData.orthoMat * localModel * vec4(vertexPos, 1.0f); + gl_Position = cameraData.projMat * localModel * vec4(vertexPos, 1.0f); // gl_Position = vec4(vertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/UI_VS.glsl b/Assets/Shaders/UI_VS.glsl index c4393b98..622cf827 100644 --- a/Assets/Shaders/UI_VS.glsl +++ b/Assets/Shaders/UI_VS.glsl @@ -34,8 +34,7 @@ layout(set = 2, binding = 0) uniform CameraData vec4 position; mat4 vpMat; mat4 viewMat; - mat4 perspectiveMat; - mat4 orthoMat; + mat4 projMat; } cameraData; void main() @@ -60,7 +59,7 @@ void main() Out.normal.rgb = normalize (Out.normal.rgb); // clip space for rendering - gl_Position = cameraData.orthoMat * worldTransform * vec4 (aVertexPos, 1.0f); + gl_Position = cameraData.projMat * worldTransform * vec4 (aVertexPos, 1.0f); gl_Position.z += 0.1f; // HAX // gl_Position = vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index 4f1586ac..a12a19f7 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -500,10 +500,7 @@ namespace SHADE imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); //auto const& renderers = gfxSystem->GetDefaultViewport()->GetRenderers(); - auto const& renderers = gfxSystem->GetEditorViewport()->GetRenderers(); - - SHASSERT(!renderers.empty(), "No Renderers available") - auto renderGraph = renderers[SHGraphicsConstants::RenderGraphIndices::EDITOR]->GetRenderGraph(); + auto renderGraph = gfxSystem->GetRenderGraph(); auto renderPass = renderGraph->GetNode("ImGui Node")->GetRenderpass(); if(ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()) == false) @@ -523,7 +520,7 @@ namespace SHADE ImGui_ImplVulkan_DestroyFontUploadObjects(); - renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle& cmd, uint32_t frameIndex) + renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle cmd, Handle renderer, uint32_t frameIndex) { cmd->BeginLabeledSegment("ImGui Draw"); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp index 05fd4288..37b89883 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp @@ -367,7 +367,7 @@ namespace SHADE } } - void SHVkCommandBuffer::BindDescriptorSet(Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span dynamicOffsets) + void SHVkCommandBuffer::BindDescriptorSet(Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span const dynamicOffsets) { uint32_t bindPointIndex = static_cast(bindPoint); vkCommandBuffer.bindDescriptorSets(SHVkUtil::GetPipelineBindPointFromType(bindPoint), bindPointData[bindPointIndex].boundPipelineLayoutHdl->GetVkPipelineLayout(), firstSet, descSetGroup->GetVkHandle(), dynamicOffsets); diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h index fc348487..c6a17d2a 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h @@ -125,7 +125,7 @@ namespace SHADE void BindPipeline (Handle const& pipelineHdl) noexcept; void BindVertexBuffer (uint32_t bindingPoint, Handle const& buffer, vk::DeviceSize offset) noexcept; void BindIndexBuffer (Handle const& buffer, uint32_t startingIndex) const noexcept; - void BindDescriptorSet (Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span dynamicOffsets); + void BindDescriptorSet (Handle descSetGroup, SH_PIPELINE_TYPE bindPoint, uint32_t firstSet, std::span const dynamicOffsets); // Draw Commands void DrawArrays (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) const noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp index 2d6cc9e1..09dbef51 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp @@ -1,10 +1,31 @@ #include "SHpch.h" #include "SHGlobalDescriptorSets.h" +#include "Graphics/MiddleEnd/Lights/SHLightingSubSystem.h" +#include "Graphics/Commands/SHVkCommandBuffer.h" namespace SHADE { - Handle SHGlobalDescriptorSets::lightDescriptorSet; + Handle SHGlobalDescriptorSets::staticGlobalDataDescriptorSet; + Handle SHGlobalDescriptorSets::lightingSubSystem; + + //void SHGlobalDescriptorSets::BindLightingData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t firstSet) noexcept + //{ + // // Bind descriptor set for light data + // cmdBuffer->BindDescriptorSet(SHGlobalDescriptorSets::GetLightDescriptorSet(), SH_PIPELINE_TYPE::COMPUTE, descMappings[SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS], const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); + //} + + void SHGlobalDescriptorSets::BindLightingData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept + { + lightingSubSystem->BindDescSet(cmdBuffer, setIndex, frameIndex); + } + + void SHGlobalDescriptorSets::BindStaticGlobalData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept + { + // Bind descriptor set for static global data + static constexpr std::array TEX_DYNAMIC_OFFSET{ 0 }; + cmdBuffer->BindDescriptorSet(staticGlobalDataDescriptorSet, pipelineType, setIndex, const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); + } /***************************************************************************/ /*! @@ -17,14 +38,14 @@ namespace SHADE */ /***************************************************************************/ - void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle lightDescSet) noexcept + void SHGlobalDescriptorSets::SetLightingSubSystem(Handle system) noexcept { - lightDescriptorSet = lightDescSet; + lightingSubSystem = system; } - Handle SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept + void SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(Handle staticGlobalDescSet) noexcept { - return lightDescriptorSet; + staticGlobalDataDescriptorSet = staticGlobalDescSet; } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h index ce6c42bb..2e2dca7d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h @@ -2,23 +2,35 @@ #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Resource/SHHandle.h" +#include "Graphics/Pipeline/SHPipelineType.h" namespace SHADE { + class SHLightingSubSystem; + class SHVkCommandBuffer; + // This class is mainly for descriptors that are truly global, meaning they only come from 1 place and they are shared between many systems class SHGlobalDescriptorSets { private: - //! Light data descriptor set - static Handle lightDescriptorSet; + + //! Static global descriptor sets for miscellaneous data and textures + static Handle staticGlobalDataDescriptorSet; + //! Lighting sub system required to get information to bind descriptor sets for light data + static Handle lightingSubSystem; + public: + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + static void BindLightingData (Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept; + static void BindStaticGlobalData (Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept; + /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static void SetLightDescriptorSet (Handle lightDescSet) noexcept; - - static Handle GetLightDescriptorSet (void) noexcept; - + static void SetLightingSubSystem (Handle system) noexcept; + static void SetStaticGlobalDataDescriptorSet (Handle staticGlobalDescSet) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp index ac7fac17..ac7ab982 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp @@ -125,33 +125,33 @@ namespace SHADE Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); - //// font bitmap data (texture) - //SHVkDescriptorSetLayout::Binding fontBitmapBinding - //{ - // .Type = vk::DescriptorType::eCombinedImageSampler, - // .Stage = vk::ShaderStageFlagBits::eFragment, - // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, - // .DescriptorCount = 1, - //}; + // font bitmap data (texture) + SHVkDescriptorSetLayout::Binding fontBitmapBinding + { + .Type = vk::DescriptorType::eCombinedImageSampler, + .Stage = vk::ShaderStageFlagBits::eFragment, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, + .DescriptorCount = 1, + }; - //// font data in the form of matrices - //SHVkDescriptorSetLayout::Binding fontMatrixBinding - //{ - // .Type = vk::DescriptorType::eStorageBuffer, - // .Stage = vk::ShaderStageFlagBits::eVertex, - // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, - // .DescriptorCount = 1, - //}; + // font data in the form of matrices + SHVkDescriptorSetLayout::Binding fontMatrixBinding + { + .Type = vk::DescriptorType::eStorageBuffer, + .Stage = vk::ShaderStageFlagBits::eVertex, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, + .DescriptorCount = 1, + }; - //Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); - //SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); + Handle fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); + SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); predefinedLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(lightDataDescSetLayout); predefinedLayouts.push_back(cameraDataGlobalLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout); - //predefinedLayouts.push_back(fontDataDescSetLayout); + predefinedLayouts.push_back(fontDataDescSetLayout); batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts ( @@ -163,7 +163,8 @@ namespace SHADE textSystemData.descSetLayouts = GetPredefinedDescSetLayouts ( SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA + SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index d77fbeb0..b57249de 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -99,10 +99,10 @@ namespace SHADE createMeshBatches(); // Register function for subpass - auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); - auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph(); + //auto const& RENDERERS = gfxSystem->GetDefaultViewport()->GetRenderers(); + auto renderGraph = gfxSystem->GetRenderGraph(); auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw"); - subPass->AddExteriorDrawCalls([this](Handle& cmdBuffer, uint32_t frameIndex) + subPass->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); cmdBuffer->BeginLabeledSegment("SHDebugDraw (No Depth Test)"); @@ -126,7 +126,7 @@ namespace SHADE cmdBuffer->EndLabeledSegment(); }); auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth"); - subPassWithDepth->AddExteriorDrawCalls([this](Handle& cmdBuffer, uint32_t frameIndex) + subPassWithDepth->AddExteriorDrawCalls([this](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { const uint32_t FRAME_IDX = gfxSystem->GetCurrentFrameIndex(); cmdBuffer->BeginLabeledSegment("SHDebugDraw (Depth Tested)"); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index c80b9de5..06ffe381 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -34,6 +34,7 @@ namespace SHADE LIGHTS = 0x02, CAMERA = 0x04, MATERIALS = 0x08, + FONT = 0x10, }; // This enum is different from the one above in that it is used to initialize a hash table to diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6881d7a8..461b8783 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -44,6 +44,7 @@ of DigiPen Institute of Technology is prohibited. #include "../Meshes/SHPrimitiveGenerator.h" #include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" namespace SHADE { @@ -142,7 +143,7 @@ namespace SHADE static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); } - void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept + void SHGraphicsSystem::InitRenderGraph(void) noexcept { /*-----------------------------------------------------------------------*/ /* MIDDLE END SETUP @@ -158,55 +159,66 @@ namespace SHADE auto cameraSystem = SHSystemManager::GetSystem(); // Set Up Cameras - screenCamera = resourceManager.Create(); - screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); - screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); + //screenCamera = resourceManager.Create(); + //screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); + //screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); - worldCamera = resourceManager.Create(); - 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(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); + //worldCamera = resourceManager.Create(); + //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(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); worldCameraDirector = cameraSystem->CreateDirector(); + /*-----------------------------------------------------------------------*/ + /* PREPARE RENDERERS */ + /*-----------------------------------------------------------------------*/ + // Add world renderer to default viewport + worldRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE); + worldRenderer->SetCameraDirector(worldCameraDirector); + + // Add screen renderer to default viewport + screenRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); + screenRenderer->SetCameraDirector(worldCameraDirector); + // Create Default Viewport worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(window->GetWindowSize().first), static_cast(window->GetWindowSize().second), 0.0f, 1.0f)); - // Get render graph from default viewport world renderer - worldRenderGraph = resourceManager.Create(); - std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) { renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; } + // Get render graph from default viewport world renderer + renderGraph = resourceManager.Create(); + /*-----------------------------------------------------------------------*/ /* WORLD RENDER GRAPH RESOURCES */ /*-----------------------------------------------------------------------*/ // Initialize world render graph - worldRenderGraph->Init("World Render Graph", device, swapchain, &resourceManager); - worldRenderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - worldRenderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); + renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); //worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - worldRenderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); - 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, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, 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, 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); + renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); + renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + renderGraph->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); + renderGraph->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); + renderGraph->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); + renderGraph->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); + renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second, vk::Format::eR8Unorm); /*-----------------------------------------------------------------------*/ /* MAIN NODE */ /*-----------------------------------------------------------------------*/ - auto gBufferNode = worldRenderGraph->AddNode("G-Buffer", + auto gBufferNode = renderGraph->AddNode("G-Buffer", { "Position", "Entity ID", "Light Layer Indices", "Normals", - //"Tangents", "Albedo", "Depth Buffer", "Scene", @@ -218,20 +230,21 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* G-BUFFER SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write"); + auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write", worldViewport, worldRenderer); gBufferSubpass->AddColorOutput("Position"); gBufferSubpass->AddColorOutput("Entity ID"); gBufferSubpass->AddColorOutput("Light Layer Indices"); gBufferSubpass->AddColorOutput("Normals"); - //gBufferSubpass->AddColorOutput("Tangents"); gBufferSubpass->AddColorOutput("Albedo"); gBufferSubpass->AddDepthOutput("Depth Buffer", SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL); + /*-----------------------------------------------------------------------*/ /* SSAO PASS AND DATA INIT */ /*-----------------------------------------------------------------------*/ ssaoStorage = resourceManager.Create(); + // command buffer operation to transfer data for ssao ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); SET_VK_OBJ_NAME(device, vk::ObjectType::eCommandBuffer, ssaoTransferCmdBuffer->GetVkCommandBuffer(), "[Command Buffer] SSAO Pass (Graphics)"); ssaoTransferCmdBuffer->BeginRecording(); @@ -240,50 +253,80 @@ namespace SHADE ssaoTransferCmdBuffer->EndRecording(); graphicsQueue->SubmitCommandBuffer({ ssaoTransferCmdBuffer }); - // Set up Debug Draw Passes - // - Depth Tested - auto debugDrawNodeDepth = worldRenderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"}); - auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth"); - debugDrawDepthSubpass->AddColorOutput("Scene"); - debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); - // - No Depth Test - auto debugDrawNode = worldRenderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" }); - auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw"); - debugDrawSubpass->AddColorOutput("Scene"); + // wait for command buffer to finish executing graphicsQueue->WaitIdle(); - ssaoStorage->PrepareRotationVectorsVkData(device); + // Add the pass to generate an image with just SSAO data Handle ssaoPass = gBufferNode->AddNodeCompute("SSAO", ssaoShader, { "Position", "Normals", "SSAO" }); auto ssaoDataBuffer = ssaoStorage->GetBuffer(); ssaoPass->ModifyWriteDescBufferComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_BUFFER_BINDING, { &ssaoDataBuffer, 1 }, 0, ssaoStorage->GetBuffer()->GetSizeStored()); auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout(); - ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, {&viewSamplerLayout, 1}); + ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 }); - - Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, {"SSAO", "SSAO Blur"}); + // Add another pass to blur SSAO + Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" }); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"}); + gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); + + /*-----------------------------------------------------------------------*/ + /* DEBUG DRAW PASS INIT */ + /*-----------------------------------------------------------------------*/ + // Set up Debug Draw Passes + // - Depth Tested + auto debugDrawNodeDepth = renderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"}); + auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer); + debugDrawDepthSubpass->AddColorOutput("Scene"); + debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); + // - No Depth Test + auto debugDrawNode = renderGraph->AddNode("Debug Draw", { "Scene" }, { "Debug Draw with Depth" }); + auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw", worldViewport, worldRenderer); + debugDrawSubpass->AddColorOutput("Scene"); + + /*-----------------------------------------------------------------------*/ + /* SCREEN SPACE PASS */ + /*-----------------------------------------------------------------------*/ + auto screenSpaceNode = renderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID" }, {"G-Buffer", "Debug Draw" }); + auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer); + uiSubpass->AddColorOutput("Scene"); + uiSubpass->AddColorOutput("Entity ID"); + uiSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) + { + textRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex); + }); + + /*-----------------------------------------------------------------------*/ + /* RENDER TO SWAPCHAIN IMAGE FOR PRESENT PASS */ + /*-----------------------------------------------------------------------*/ +#ifdef SHEDITOR { - //// 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 = renderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" }); + auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass", {}, {}); + dummySubpass->AddInput("Scene"); + + auto imGuiNode = renderGraph->AddNode("ImGui Node", { "Present" }, {}); + auto imGuiSubpass = imGuiNode->AddSubpass("ImGui Draw", {}, {}); + imGuiSubpass->AddColorOutput("Present"); } +#else + renderGraph->AddRenderToSwapchainNode("Scene", "Present", { "Screen Space Pass" }, { renderToSwapchainVS, renderToSwapchainFS }); +#endif + /*-----------------------------------------------------------------------*/ - /* GENERATE WORLD RENDER GRAPH */ + /* GENERATE RENDER GRAPH */ /*-----------------------------------------------------------------------*/ - // Generate world render graph - worldRenderGraph->Generate(); - + // Generate render graph + renderGraph->Generate(); +#if 0 /*-----------------------------------------------------------------------*/ /* SCREEN RENDER GRAPH */ /*-----------------------------------------------------------------------*/ @@ -317,18 +360,7 @@ namespace SHADE screenRenderGraph->Generate(); - /*-----------------------------------------------------------------------*/ - /* BIND RENDER GRAPH TO RENDERER */ - /*-----------------------------------------------------------------------*/ - // Add world renderer to default viewport - worldRenderer = worldViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[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, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], screenRenderGraph); - screenRenderer->SetCamera(screenCamera); - screenRenderer->SetCameraDirector(worldCameraDirector); +#endif // Create debug draw pipeline debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, false); @@ -361,10 +393,12 @@ namespace SHADE { SHPredefinedData::Init(device); - InitSceneRenderGraph(); + InitRenderGraph(); -#ifdef SHEDITOR - InitEditorRenderGraph(); +#if 0 + #ifdef SHEDITOR + InitEditorRenderGraph(); + #endif #endif // Create Semaphore @@ -377,7 +411,7 @@ namespace SHADE void SHGraphicsSystem::InitSubsystems(void) noexcept { - mousePickSystem = resourceManager.Create(); + mousePickSubSystem = resourceManager.Create(); std::vector> cmdPools; cmdPools.reserve(swapchain->GetNumImages()); @@ -385,11 +419,11 @@ namespace SHADE cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]); // Mouse picking system for the editor (Will still run with editor disabled) - mousePickSystem->Init(device, cmdPools, worldRenderGraph->GetRenderGraphResource("Entity ID")); + mousePickSubSystem->Init(device, cmdPools, renderGraph->GetRenderGraphResource("Entity ID")); // Register the post offscreen render to the system - postOffscreenRender = resourceManager.Create(); - postOffscreenRender->Init(device, worldRenderGraph->GetRenderGraphResource("Scene"), descPool); + postOffscreenRenderSubSystem = resourceManager.Create(); + postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool); lightingSubSystem = resourceManager.Create(); lightingSubSystem->Init(device, descPool); @@ -397,11 +431,11 @@ namespace SHADE textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer - auto uiNode = screenRenderGraph->GetNode("Screen Space Pass"); - textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS, [=](Handle cmdBuffer, uint32_t frameIndex) - { - screenRenderer->BindDescSet(cmdBuffer, frameIndex); - }); + auto uiNode = renderGraph->GetNode("Screen Space Pass"); + textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); + + SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(texLibrary.GetTextureDescriptorSetGroup()); + SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); } @@ -425,41 +459,42 @@ namespace SHADE defaultMaterial = AddMaterial ( defaultVertShader, defaultFragShader, - worldRenderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") + renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") ); defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } -#ifdef SHEDITOR - void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept - { - auto windowDims = window->GetWindowSize(); +#if 0 + #ifdef SHEDITOR + void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept + { + auto windowDims = window->GetWindowSize(); - // Create Default Viewport - editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 1.0f)); + // Create Default Viewport + editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 1.0f)); - // Get render graph from viewport editor renderer - editorRenderGraph = resourceManager.Create(); + // Get render graph from viewport editor renderer + editorRenderGraph = resourceManager.Create(); - std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; - for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) - renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; + std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; + for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) + renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; - editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager); - editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); + editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager); + editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); - auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {}); - auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); - imguiSubpass->AddColorOutput("Present"); + auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {}); + auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); + imguiSubpass->AddColorOutput("Present"); - // Generate world render graph - editorRenderGraph->Generate(); + // Generate world render graph + editorRenderGraph->Generate(); - // Add world renderer to default viewport - editorRenderer = editorViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], editorRenderGraph); - editorRenderer->SetCamera(worldCamera); - } + // Add world renderer to default viewport + editorRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE); + } + #endif #endif /*---------------------------------------------------------------------------------*/ @@ -547,6 +582,41 @@ namespace SHADE textRenderingSubSystem->Run(frameIndex); + + for (auto renderer : renderers) + { +#ifdef SHEDITOR + if (renderer == worldRenderer) + { + auto editorSystem = SHSystemManager::GetSystem(); + if (editorSystem->editorState != SHEditor::State::PLAY) + worldRenderer->UpdateDataManual(frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix()); + else + renderer->UpdateData(frameIndex); + } + else + renderer->UpdateData(frameIndex); +#else + renderers[renIndex]->UpdateDataAndBind(frameIndex); +#endif + } + + renderGraph->Begin(frameIndex); + auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); + + // Bind all the buffers required for meshes + for (auto& [buffer, bindingPoint] : MESH_DATA) + { + if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer) + cmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0); + else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer) + cmdBuffer->BindIndexBuffer(buffer, 0); + } + + renderGraph->Execute(frameIndex, descPool); + renderGraph->End(frameIndex); + +#if 0 // For every viewport for (int vpIndex = 0; vpIndex < static_cast(viewports.size()); ++vpIndex) { @@ -564,10 +634,10 @@ namespace SHADE // Begin recording the command buffer currentCmdBuffer->BeginRecording(); - // set viewport and scissor - uint32_t w = static_cast(viewports[vpIndex]->GetWidth()); - uint32_t h = static_cast(viewports[vpIndex]->GetHeight()); - currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); + //// set viewport and scissor + //uint32_t w = static_cast(viewports[vpIndex]->GetWidth()); + //uint32_t h = static_cast(viewports[vpIndex]->GetHeight()); + //currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); // Force set the pipeline layout currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); @@ -601,20 +671,20 @@ namespace SHADE // bind camera data //renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -#ifdef SHEDITOR - if (renderers[renIndex] == worldRenderer) - { - auto editorSystem = SHSystemManager::GetSystem(); - if (editorSystem->editorState != SHEditor::State::PLAY) - worldRenderer->UpdateDataAndBind(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix()); - else - renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); - } - else - renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -#else - renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -#endif +//#ifdef SHEDITOR +// if (renderers[renIndex] == worldRenderer) +// { +// auto editorSystem = SHSystemManager::GetSystem(); +// if (editorSystem->editorState != SHEditor::State::PLAY) +// worldRenderer->UpdateDataManual(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix()); +// else +// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); +// } +// else +// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); +//#else +// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); +//#endif // Draw the scene renderers[renIndex]->Draw(frameIndex, descPool); @@ -638,8 +708,10 @@ namespace SHADE semIndex = !semIndex; } } +#endif } + /***************************************************************************/ /*! @@ -677,12 +749,8 @@ namespace SHADE // #BackEndTest: For for the fence initialized by queue submit renderContext.WaitForFence(); - // Finalise all batches - for (auto vp : viewports) - for (auto renderer : vp->GetRenderers()) - { - renderer->GetRenderGraph()->FinaliseBatch(renderContext.GetCurrentFrame(), descPool); - } + // finalize batches for render graph + renderGraph->FinaliseBatch(renderContext.GetCurrentFrame(), descPool); // #BackEndTest: Acquire the next image in the swapchain available renderContext.AcquireNextIamge(); @@ -723,7 +791,7 @@ namespace SHADE const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); auto& currFrameData = renderContext.GetCurrentFrameData(); - mousePickSystem->Run(graphicsQueue, CURR_FRAME_IDX); + mousePickSubSystem->Run(graphicsQueue, CURR_FRAME_IDX); // #BackEndTest: queues an image for presentation if (auto result = graphicsQueue->Present(swapchain, { currFrameData.semRenderFinishHdl }, CURR_FRAME_IDX); result != vk::Result::eSuccess) @@ -763,6 +831,40 @@ namespace SHADE viewports.erase(iter); } + /*---------------------------------------------------------------------------------*/ + /* Renderer Registration Functions */ + /*---------------------------------------------------------------------------------*/ + Handle SHGraphicsSystem::AddRenderer(SHRenderer::PROJECTION_TYPE projectionType) + { + std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; + for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) + { + renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; + } + + // Create the renderer + auto renderer = resourceManager.Create(device, swapchain->GetNumImages(), renderContextCmdPools, descPool); + + // Store + renderers.emplace_back(renderer); + + // Return + return renderer; + } + void SHGraphicsSystem::RemoveRenderer(Handle renderer) + { + auto iter = std::find(renderers.begin(), renderers.end(), renderer); + if (iter == renderers.end()) + { + SHLOG_WARNING("Attempted to remove a Renderer that does not belong to a viewport!"); + return; + } + + // Remove it + iter->Free(); + renderers.erase(iter); + } + Handle SHGraphicsSystem::AddMaterial(Handle vertShader, Handle fragShader, Handle subpass) { // Retrieve pipeline from pipeline storage or create if unavailable @@ -1058,7 +1160,7 @@ namespace SHADE renderContext.HandleResize(); - worldRenderGraph->HandleResize(resizeWidth, resizeHeight); + renderGraph->HandleResize(resizeWidth, resizeHeight); #ifdef SHEDITOR @@ -1067,13 +1169,13 @@ namespace SHADE //editorViewport->SetWidth(windowDims.first); //editorViewport->SetHeight(windowDims.second); - editorRenderGraph->HandleResize(windowDims.first, windowDims.second); + //editorRenderGraph->HandleResize(windowDims.first, windowDims.second); #endif - screenRenderGraph->HandleResize(resizeWidth, resizeHeight); + //screenRenderGraph->HandleResize(resizeWidth, resizeHeight); - mousePickSystem->HandleResize(); - postOffscreenRender->HandleResize(); + mousePickSubSystem->HandleResize(); + postOffscreenRenderSubSystem->HandleResize(); worldViewport->SetWidth(static_cast(resizeWidth)); worldViewport->SetHeight(static_cast(resizeHeight)); @@ -1102,9 +1204,14 @@ namespace SHADE } + Handle SHGraphicsSystem::GetRenderGraph(void) const noexcept + { + return renderGraph; + } + Handle SHGraphicsSystem::GetPrimaryRenderpass() const noexcept { - return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); + return renderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); } Handle SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept @@ -1137,7 +1244,7 @@ namespace SHADE device, SHPipelineLayoutParams { .shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader }, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA) + .predefinedDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA) } ); auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 75b48c9b..0aa83f21 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -34,6 +34,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/PostProcessing/SHSSAO.h" #include "Camera/SHCameraDirector.h" #include "Graphics/MiddleEnd/TextRendering/SHFontLibrary.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" namespace SHADE { @@ -49,7 +50,6 @@ namespace SHADE class SHVkImage; class SHVkFramebuffer; class SHVkCommandBuffer; - class SHRenderer; class SHViewport; class SHCamera; class SHVkShaderModule; @@ -99,7 +99,7 @@ namespace SHADE { private: void InitBoilerplate (void) noexcept; - void InitSceneRenderGraph (void) noexcept; + void InitRenderGraph (void) noexcept; void InitMiddleEnd (void) noexcept; void InitSubsystems (void) noexcept; void InitBuiltInResources (void); @@ -171,6 +171,13 @@ namespace SHADE Handle AddViewport(const vk::Viewport& viewport); void RemoveViewport(Handle viewport); + /*-----------------------------------------------------------------------------*/ + /* Renderers Registration Functions */ + /*-----------------------------------------------------------------------------*/ + Handle AddRenderer(SHRenderer::PROJECTION_TYPE projectionType); + void RemoveRenderer(Handle renderer); + + /*-----------------------------------------------------------------------------*/ /* Material Functions */ /*-----------------------------------------------------------------------------*/ @@ -382,8 +389,9 @@ namespace SHADE #ifdef SHEDITOR Handle GetEditorViewport () const {return editorViewport;}; #endif - Handle GetMousePickSystem(void) const noexcept {return mousePickSystem;}; - Handle GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;}; + Handle GetMousePickSystem(void) const noexcept {return mousePickSubSystem;}; + Handle GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRenderSubSystem;}; + Handle GetRenderGraph (void) const noexcept; Handle GetPrimaryRenderpass() const noexcept; Handle GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept; uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); } @@ -441,10 +449,8 @@ namespace SHADE // Renderers Handle worldRenderer; Handle screenRenderer; + std::vector> renderers; - // Temp Cameras - Handle worldCamera; - Handle screenCamera; DirectorHandle worldCameraDirector; @@ -483,15 +489,15 @@ namespace SHADE std::array, MAX_PRIMITIVE_TYPES> primitiveMeshes; // Render Graphs - Handle worldRenderGraph; - Handle screenRenderGraph; + Handle renderGraph; + //Handle screenRenderGraph; #ifdef SHEDITOR - Handle editorRenderGraph; + //Handle editorRenderGraph; #endif // Sub systems - Handle mousePickSystem; - Handle postOffscreenRender; + Handle mousePickSubSystem; + Handle postOffscreenRenderSubSystem; Handle lightingSubSystem; Handle textRenderingSubSystem; Handle ssaoStorage; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index 1136a2c9..be9f0482 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -14,7 +14,6 @@ of DigiPen Institute of Technology is prohibited. #include "SHRenderer.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "SHViewport.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Framebuffer/SHVkFramebuffer.h" #include "SHMaterial.h" @@ -22,22 +21,22 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Camera/SHCameraDirector.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Constructor/Destructors */ /*-----------------------------------------------------------------------------------*/ - SHRenderer::SHRenderer(Handle logicalDevice, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle viewport, Handle renderGraph) - : viewport { viewport } - , renderGraph { renderGraph } + SHRenderer::SHRenderer(Handle logicalDevice, uint32_t numFrames, Handle descriptorPool, PROJECTION_TYPE type) + : projectionType{type} { - commandBuffers.resize(static_cast(numFrames)); + //commandBuffers.resize(static_cast(numFrames)); - for (uint32_t i = 0; i < commandBuffers.size(); ++i) - commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); + //for (uint32_t i = 0; i < commandBuffers.size(); ++i) + // commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); - cameraDescriptorSet = descriptorPool->Allocate({ cameraDescLayout }, { 1 }); + cameraDescriptorSet = descriptorPool->Allocate(SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA), { 1 }); #ifdef _DEBUG const auto& CAM_DESC_SETS = cameraDescriptorSet->GetVkHandle(); @@ -61,18 +60,6 @@ namespace SHADE SHRenderer::~SHRenderer(void) { - //for (auto& cmdBuffer : commandBuffers) - //{ - // cmdBuffer.Free(); - //} - } - - /*-----------------------------------------------------------------------------------*/ - /* Camera Registration */ - /*-----------------------------------------------------------------------------------*/ - void SHRenderer::SetCamera(Handle _camera) - { - camera = _camera; } void SHRenderer::SetCameraDirector(Handle director) noexcept @@ -80,63 +67,55 @@ namespace SHADE cameraDirector = director; } - /*-----------------------------------------------------------------------------------*/ - /* Drawing Functions */ - /*-----------------------------------------------------------------------------------*/ - void SHRenderer::Draw(uint32_t frameIndex, Handle descPool) noexcept + void SHRenderer::UpdateData(uint32_t frameIndex) noexcept { - renderGraph->Execute(frameIndex, commandBuffers[frameIndex], descPool); - } - - void SHRenderer::UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex) noexcept - { - if (camera && cameraDirector) + if (cameraDirector) { - //UpdateDataAndBind(cmdBuffer, frameIndex, SHMatrix::Transpose(cameraDirector->GetVPMatrix())); - UpdateDataAndBind(cmdBuffer, frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix(), cameraDirector->GetOrthoMatrix()); + switch (projectionType) + { + case PROJECTION_TYPE::DEFAULT: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix()); + break; + case PROJECTION_TYPE::PERSPECTIVE: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetPerspectiveMatrix()); + break; + case PROJECTION_TYPE::ORTHOGRAPHIC: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetOrthoMatrix()); + break; + default: + UpdateDataManual(frameIndex, cameraDirector->GetViewMatrix(), cameraDirector->GetProjMatrix()); + break; + } } } - void SHRenderer::UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept + void SHRenderer::UpdateDataManual(uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept { - SetViewProjectionMatrix(viewMatrix, projMatrix, orthoMatrix); + SetViewProjectionMatrix(viewMatrix, projMatrix); - //cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix(); cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex); - BindDescSet(cmdBuffer, frameIndex); + //BindDescSet(cmdBuffer, frameIndex); } - void SHRenderer::BindDescSet(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHRenderer::BindDescriptorSet(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept { std::array dynamicOffsets{ frameIndex * cameraDataAlignedSize }; - cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 }); - cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 }); + cmdBuffer->BindDescriptorSet(cameraDescriptorSet, pipelineType, setIndex, std::span{ dynamicOffsets.data(), 1 }); } - void SHRenderer::UpdateCameraDataToBuffer(void) noexcept + void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept { - } - - void SHRenderer::SetViewProjectionMatrix(SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept - { - //cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix(); cpuCameraData.viewProjectionMatrix = SHMatrix::Transpose(projMatrix * viewMatrix); cpuCameraData.viewMatrix = SHMatrix::Transpose(viewMatrix); cpuCameraData.projectionMatrix = SHMatrix::Transpose(projMatrix); - cpuCameraData.orthoMatrix = SHMatrix::Transpose (orthoMatrix); } - Handle SHRenderer::GetRenderGraph(void) const noexcept - { - return renderGraph; - } - - Handle SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept - { - return commandBuffers[frameIndex]; - } + //Handle SHRenderer::GetCommandBuffer(uint32_t frameIndex) const noexcept + //{ + // return commandBuffers[frameIndex]; + //} Handle SHRenderer::GetCameraDirector(void) const noexcept { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 4bd205be..c93050d7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -32,7 +32,6 @@ namespace SHADE class SHVkFramebuffer; class SHMaterial; class SHVkLogicalDevice; - class SHViewport; class SHVkImageView; class SHVkCommandBuffer; class SHCamera; @@ -48,7 +47,6 @@ namespace SHADE SHMatrix viewProjectionMatrix; SHMatrix viewMatrix; SHMatrix projectionMatrix; - SHMatrix orthoMatrix; }; /*---------------------------------------------------------------------------------*/ @@ -64,35 +62,36 @@ namespace SHADE /***********************************************************************************/ class SHRenderer { - public: + enum class PROJECTION_TYPE + { + DEFAULT, + PERSPECTIVE, + ORTHOGRAPHIC + }; + /*-----------------------------------------------------------------------------*/ /* Constructor/Destructors */ /*-----------------------------------------------------------------------------*/ - SHRenderer(Handle logicalDevice, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle viewport, Handle renderGraph); + SHRenderer(Handle logicalDevice, uint32_t numFrames, Handle descriptorPool, PROJECTION_TYPE type); ~SHRenderer(void); /*-----------------------------------------------------------------------------*/ /* Camera Registration */ /*-----------------------------------------------------------------------------*/ - void SetCamera(Handle _camera); void SetCameraDirector (Handle director) noexcept; /*-----------------------------------------------------------------------------*/ /* Drawing Functions */ /*-----------------------------------------------------------------------------*/ - void Draw(uint32_t frameIndex, Handle descPool) noexcept; - void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex) noexcept; - void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t frameIndex) noexcept; - void UpdateCameraDataToBuffer (void) noexcept; - void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix, SHMatrix const& orthoMatrix) noexcept; + void UpdateData(uint32_t frameIndex) noexcept; + void UpdateDataManual(uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; + void BindDescriptorSet (Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept; + void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; /*-----------------------------------------------------------------------------*/ /* Setters and Getters */ /*-----------------------------------------------------------------------------*/ - Handle GetRenderGraph (void) const noexcept; - Handle GetCommandBuffer(uint32_t frameIndex) const noexcept; Handle GetCameraDirector (void) const noexcept; private: @@ -102,9 +101,6 @@ namespace SHADE //! Vulkan UBOs need to be aligned, this is pad SHShaderCameraData struct uint32_t cameraDataAlignedSize; - Handle viewport; - Handle camera; - Handle renderGraph; Handle cameraDescriptorSet; Handle cameraBuffer; @@ -114,10 +110,10 @@ namespace SHADE // GPU. SHShaderCameraData cpuCameraData; - //! Command buffers for the render graph - std::vector> commandBuffers; - + ////! Command buffers for the render graph + //std::vector> commandBuffers; + PROJECTION_TYPE projectionType; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp index 7bd0049f..078261a5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp @@ -46,34 +46,6 @@ namespace SHADE ); } - /*---------------------------------------------------------------------------------*/ - /* Renderer Registration Functions */ - /*---------------------------------------------------------------------------------*/ - Handle SHViewport::AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph) - { - // Create the renderer - auto renderer = resourceManager.Create(device, numFrames, cmdPools, descriptorPool, cameraDescLayout, GetHandle(), renderGraph); - - // Store - renderers.emplace_back(renderer); - - // Return - return renderer; - } - void SHViewport::RemoveRenderer(Handle renderer) - { - auto iter = std::find(renderers.begin(), renderers.end(), renderer); - if (iter == renderers.end()) - { - SHLOG_WARNING("Attempted to remove a Renderer that does not belong to a viewport!"); - return; - } - - // Remove it - iter->Free(); - renderers.erase(iter); - } - void SHViewport::SetWidth(float w) noexcept { viewport.width = w; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h index 26c0a6bd..60bd6e95 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h @@ -56,11 +56,11 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ void SetUp(Handle commandBuffer); - /*-----------------------------------------------------------------------------*/ - /* Renderers Registration Functions */ - /*-----------------------------------------------------------------------------*/ - Handle AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); - void RemoveRenderer(Handle renderer); + ///*-----------------------------------------------------------------------------*/ + ///* Renderers Registration Functions */ + ///*-----------------------------------------------------------------------------*/ + //Handle AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); + //void RemoveRenderer(Handle renderer); /*-----------------------------------------------------------------------------*/ /* Setters */ @@ -79,7 +79,7 @@ namespace SHADE float GetHeight() const { return viewport.height; } float GetMinDepth() const { return viewport.minDepth; } float GetMaxDepth() const { return viewport.maxDepth; } - std::vector>& GetRenderers() { return renderers; } + //std::vector>& GetRenderers() { return renderers; } private: @@ -88,7 +88,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ Handle device; vk::Viewport viewport; - std::vector> renderers; + //std::vector> renderers; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 448c3bed..abbf88c3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -385,7 +385,7 @@ namespace SHADE std::fill (variableSizes.begin(), variableSizes.end(), 1); // Create the descriptor set - lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS] }, variableSizes); + lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS) }, variableSizes); #ifdef _DEBUG const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle(); for (int i = 0; i < static_cast(CAM_DESC_SETS.size()); ++i) @@ -517,11 +517,16 @@ namespace SHADE } - void SHLightingSubSystem::BindDescSet(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHLightingSubSystem::BindDescSet(Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept { //Bind descriptor set(We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data). - cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, { dynamicOffsets[frameIndex] }); + cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, setIndex, { dynamicOffsets[frameIndex] }); } + Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept + { + return lightingDataDescSet; + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index ae6caead..fa103136 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -4,6 +4,7 @@ #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec4.h" #include "SHLightData.h" +#include #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" namespace SHADE @@ -57,8 +58,11 @@ namespace SHADE class SH_API SHLightingSubSystem { - private: + public: + using DynamicOffsetArray = std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)>; + + private: class PerTypeData { private: @@ -130,7 +134,7 @@ namespace SHADE std::array(SH_LIGHT_TYPE::NUM_TYPES)> perTypeData; //! Container to store dynamic offsets for binding descriptor sets - std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)> dynamicOffsets; + DynamicOffsetArray dynamicOffsets; //! holds the data that represents how many lights are in the scene std::array(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData; @@ -162,7 +166,8 @@ namespace SHADE void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; void Exit (void) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t frameIndex) noexcept; + void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; + Handle GetLightDataDescriptorSet (void) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index f117b26c..f9afa48f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -11,6 +11,8 @@ #include "Graphics/SHVkUtil.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Math/Transform/SHTransformComponent.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" namespace SHADE { @@ -91,12 +93,10 @@ namespace SHADE } - void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept + void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept { SHComponentManager::CreateComponentSparseSet(); - cameraDescSetBind = bindFunction; - logicalDevice = device; // prepare pipeline layout params @@ -174,9 +174,14 @@ namespace SHADE } } - void SHTextRenderingSubSystem::Render(Handle cmdBuffer, uint32_t frameIndex) noexcept + void SHTextRenderingSubSystem::Render(Handle cmdBuffer, Handle renderer, uint32_t frameIndex) noexcept { auto& textRendererComps = SHComponentManager::GetDense(); + auto const& mappings = SHPredefinedData::GetTextSystemData().descMappings; + uint32_t fontSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::FONT); + uint32_t staticGlobalSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA); + uint32_t cameraSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA); + for (auto& comp : textRendererComps) { auto* transform = SHComponentManager::GetComponent(comp.GetEID()); @@ -187,16 +192,19 @@ namespace SHADE // bind the pipeline cmdBuffer->BindPipeline(pipeline); + // Bind global data + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, staticGlobalSetIndex); + + // Bind camera data + renderer->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, cameraSetIndex, frameIndex); + + // bind descriptors for font (matrices) + cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, fontSetIndex, {}); + // bind VBO (position and indices) cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); - // bind camera desc set (again). Necessary because pipeline layout is not compatible. - cameraDescSetBind(cmdBuffer, frameIndex); - - // bind descriptors for font (matrices) - cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, {}); - cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS); cmdBuffer->SetPushConstantVariable("TestPushConstant.eid", comp.GetEID(), SH_PIPELINE_TYPE::GRAPHICS); cmdBuffer->SetPushConstantVariable("TestPushConstant.textColor", SHVec3 (1.0f, 1.0f, 1.0f), SH_PIPELINE_TYPE::GRAPHICS); @@ -206,9 +214,7 @@ namespace SHADE // call draw call cmdBuffer->DrawArrays(4, comp.text.size(), 0, 0); //glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, static_cast(textComp.lastRenderedCharacterIndex) + 1); - } - } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index 78b363d4..c9a89129 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -43,18 +43,14 @@ namespace SHADE //! Descriptor set for font data access in shaders //Handle fontDataDescSetLayout; - //! Super temporary. Global descriptor set needs to be revamped along with - //! entire graphics system. - std::function, uint32_t)> cameraDescSetBind; - private: void RecomputePositions(SHTextRenderableComponent& textComp) noexcept; public: - void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept; + void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept; void Run(uint32_t frameIndex) noexcept; - void Render (Handle cmdBuffer, uint32_t frameIndex) noexcept; + void Render (Handle cmdBuffer, Handle renderer, uint32_t frameIndex) noexcept; void Exit(void) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index fc029161..d431cf47 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -14,6 +14,8 @@ #include "Tools/Utilities/SHUtilities.h" #include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" #include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" + namespace SHADE { @@ -424,7 +426,7 @@ namespace SHADE */ /***************************************************************************/ - void SHRenderGraph::Init(std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub) noexcept + void SHRenderGraph::Init(std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub, std::vector>& cmdPools) noexcept { //resourceHub = std::make_shared(); @@ -437,6 +439,11 @@ namespace SHADE renderGraphStorage->resourceHub = resourceHub; renderGraphStorage->descriptorPool = logicalDevice->CreateDescriptorPools(); + commandBuffers.resize(static_cast(swapchain->GetNumImages())); + + for (uint32_t i = 0; i < commandBuffers.size(); ++i) + commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); + name = std::move(graphName); } @@ -555,16 +562,22 @@ namespace SHADE if (renderGraphStorage->graphResources->contains(toSwapchainResource) && renderGraphStorage->graphResources->contains(swapchainResource)) { auto newNode = AddNode("Render To Present", { ResourceInstruction (toSwapchainResource.c_str()), ResourceInstruction(swapchainResource.c_str()) }, predecessorNodes); - auto newSubpass = newNode->AddSubpass("Render"); + auto newSubpass = newNode->AddSubpass("Render", {}, {}); newSubpass->AddColorOutput(swapchainResource); newSubpass->AddInput(toSwapchainResource); renderToSwapchainImageSystem = renderGraphStorage->resourceHub->Create (newNode, newSubpass, shaderModules); - newSubpass->AddExteriorDrawCalls([=](Handle& cmdBuffer, uint32_t frameIndex) + newSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) { cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline()); - + + // If we are rendering to present image, the width and height will be the dimensions of that image. So we need to set viewport scissor. + auto resource = renderGraphStorage->graphResources->at(swapchainResource); + uint32_t w = static_cast(resource->GetWidth()); + uint32_t h = static_cast(resource->GetHeight()); + cmdBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); + newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex); // draw a quad. @@ -616,14 +629,39 @@ namespace SHADE // TODO: The graph scope buffers were meant to bind vertex buffers and index buffers for meshes. Find a // better way to manage these - void SHRenderGraph::Execute(uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept + void SHRenderGraph::Execute(uint32_t frameIndex, Handle descPool) noexcept { + auto cmdBuffer = commandBuffers[frameIndex]; cmdBuffer->BeginLabeledSegment(name); + + // Force bind pipeline layout + cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::GRAPHICS); + cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); + + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + for (auto& node : nodes) + { + // bind static global data + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + node->Execute(cmdBuffer, descPool, frameIndex); + } + cmdBuffer->EndLabeledSegment(); } + void SHRenderGraph::Begin(uint32_t frameIndex) noexcept + { + commandBuffers[frameIndex]->BeginRecording(); + + } + + void SHRenderGraph::End(uint32_t frameIndex) noexcept + { + commandBuffers[frameIndex]->EndRecording(); + } + void SHRenderGraph::FinaliseBatch(uint32_t frameIndex, Handle descPool) { for (auto& node : nodes) @@ -670,4 +708,9 @@ namespace SHADE return {}; } + Handle SHRenderGraph::GetCommandBuffer(uint32_t frameIndex) const noexcept + { + return commandBuffers[frameIndex]; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index f892483f..c69e83b1 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -74,6 +74,9 @@ namespace SHADE //! For rendering onto the swapchain Handle renderToSwapchainImageSystem; + //! Command buffer to issue rendering commands + std::vector> commandBuffers; + public: /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ @@ -86,7 +89,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub) noexcept; + void Init (std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub, std::vector>& cmdPools) noexcept; void AddResource(std::string resourceName, std::initializer_list typeFlags, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageUsageFlagBits usageFlags = {}, vk::ImageCreateFlagBits createFlags = {}); void LinkNonOwningResource (Handle resourceOrigin, std::string resourceName) noexcept; Handle AddNode (std::string nodeName, std::initializer_list resourceInstruction, std::initializer_list predecessorNodes) noexcept; @@ -94,16 +97,19 @@ namespace SHADE void Generate (void) noexcept; void CheckForNodeComputes (void) noexcept; - void Execute (uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept; + void Execute (uint32_t frameIndex, Handle descPool) noexcept; + void Begin (uint32_t frameIndex) noexcept; + void End (uint32_t frameIndex) noexcept; void FinaliseBatch (uint32_t frameIndex, Handle descPool); void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - Handle GetNode (std::string const& nodeName) const noexcept; - std::vector> const& GetNodes (void) const noexcept; - Handle GetRenderGraphResource (std::string const& resourceName) const noexcept; + Handle GetNode (std::string const& nodeName) const noexcept; + std::vector> const& GetNodes (void) const noexcept; + Handle GetRenderGraphResource (std::string const& resourceName) const noexcept; + Handle GetCommandBuffer (uint32_t frameIndex) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 0f9379fe..1d8cea62 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -9,6 +9,8 @@ #include "SHRenderGraphStorage.h" #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "Graphics/SHVkUtil.h" +#include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" namespace SHADE { @@ -238,7 +240,7 @@ namespace SHADE */ /***************************************************************************/ - Handle SHRenderGraphNode::AddSubpass(std::string subpassName) noexcept + Handle SHRenderGraphNode::AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept { // if subpass already exists, don't add. if (subpassIndexing.contains(subpassName)) @@ -253,6 +255,8 @@ namespace SHADE graphStorage->resourceHub->Create ( subpassName, + viewport, + renderer, graphStorage, GetHandle(), static_cast(subpasses.size()), resourceAttachmentMapping.get() ) @@ -318,7 +322,7 @@ namespace SHADE } // insert them all for a subpass to transition them. This subpass is the last subpass - auto dummySubpass = AddSubpass("dummy"); + auto dummySubpass = AddSubpass("dummy", {}, {}); for (auto& resource : resourcesInvolved) { dummySubpass->AddGeneralInput(resource); @@ -331,7 +335,7 @@ namespace SHADE } } - void SHRenderGraphNode::Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept + void SHRenderGraphNode::Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0; commandBuffer->BeginRenderpass(renderpass, framebuffers[framebufferIndex]); @@ -347,10 +351,14 @@ namespace SHADE commandBuffer->EndRenderpass(); + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; // Execute all subpass computes for (auto& sbCompute : nodeComputes) { + // bind lighting data + SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex); + sbCompute->Execute(commandBuffer, frameIndex); } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 2311ee0c..f7e55d4a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -22,6 +22,8 @@ namespace SHADE class SHPredefinedData; class SHRenderGraphStorage; class SHRenderGraphNodeCompute; + class SHRenderer; + class SHViewport; class SH_API SHRenderGraphNode : public ISelfHandle { @@ -102,12 +104,12 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - Handle AddSubpass(std::string subpassName) noexcept; + Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, float numWorkGroupScale = 1.0f) noexcept; void AddDummySubpassIfNeeded (void) noexcept; // TODO: RemoveSubpass() - void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; + void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; Handle GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept; void FinaliseBatch(uint32_t frameIndex, Handle descPool); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 580f018c..a9a6ac68 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -50,6 +50,8 @@ namespace SHADE //! Compute resources Handle computeResource; + //! + //! vector of resources needed by the subpass compute std::vector> resources; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index c1d53632..e5052f59 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -11,6 +11,9 @@ #include "Graphics/Swapchain/SHVkSwapchain.h" #include "Graphics/Images/SHVkSampler.h" #include "SHRenderGraphResource.h" +#include "Graphics/MiddleEnd/Interface/SHViewport.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" namespace SHADE { @@ -30,7 +33,7 @@ namespace SHADE */ /***************************************************************************/ - SHSubpass::SHSubpass(const std::string& name, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept + SHSubpass::SHSubpass(const std::string& name, Handle inViewport, Handle inRenderer, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept : resourceAttachmentMapping{ mapping } , parentNode{ parent } , subpassIndex{ index } @@ -41,6 +44,8 @@ namespace SHADE , name { name } , graphStorage{ renderGraphStorage } , inputImageDescriptorSets{} + , viewport {inViewport} + , renderer {inRenderer} { } @@ -71,6 +76,8 @@ namespace SHADE , inputDescriptorLayout{ rhs.inputDescriptorLayout } , inputSamplers{ rhs.inputSamplers } , name { rhs.name } + , viewport {rhs.viewport} + , renderer {rhs.renderer} { } @@ -106,6 +113,9 @@ namespace SHADE inputDescriptorLayout = rhs.inputDescriptorLayout; inputSamplers = rhs.inputSamplers; name = std::move(rhs.name); + renderer = rhs.renderer; + viewport = rhs.viewport; + return *this; } @@ -199,21 +209,33 @@ namespace SHADE inputReferences.push_back({ resourceAttachmentMapping->at(graphStorage->graphResources->at(resourceToReference).GetId().Raw), vk::ImageLayout::eGeneral }); } - void SHSubpass::Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept + void SHSubpass::Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { commandBuffer->BeginLabeledSegment(name); - // Ensure correct transforms are provided superBatch->UpdateBuffers(frameIndex, descPool); + if (viewport) + { + // set viewport and scissor + uint32_t w = static_cast(viewport->GetWidth()); + uint32_t h = static_cast(viewport->GetHeight()); + commandBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); + } + + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + + if (renderer) + renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + // Draw all the batches superBatch->Draw(commandBuffer, frameIndex); // Draw all the exterior draw calls for (auto& drawCall : exteriorDrawCalls) { - drawCall(commandBuffer, frameIndex); + drawCall(commandBuffer, renderer, frameIndex); } commandBuffer->EndLabeledSegment(); } @@ -231,7 +253,7 @@ namespace SHADE } } - void SHSubpass::AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept + void SHSubpass::AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept { exteriorDrawCalls.push_back(newDrawCall); } @@ -266,7 +288,7 @@ namespace SHADE } // We build a new descriptor set layout to store our images - inputDescriptorLayout = graphStorage->logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, bindings); + inputDescriptorLayout = graphStorage->logicalDevice->CreateDescriptorSetLayout(bindings); // we store a sampler if its an input attachment. if it is storage image, no need sampler, store an empty handle. for (uint32_t i = 0; i < bindings.size(); ++i) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 69b8fd56..b5c5c8b1 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -19,15 +19,28 @@ namespace SHADE class SHRenderGraphStorage; class SHVkShaderModule; class SHVkSampler; + class SHRenderer; + class SHViewport; class SH_API SHSubpass : public ISelfHandle { + public: + using ExteriorDrawCallFunction = std::function, Handle, uint32_t)>; + private: /*---------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ /*---------------------------------------------------------------------*/ Handle graphStorage; + //! Viewport to specify what part of the screen we want to draw on. This + //! will be used in vkCmdSetViewport/Scissor. + Handle viewport; + + //! Renderer used during the subpass execution. This dictates what matrix gets + //! passed to the shaders. + Handle renderer; + //! The index of the subpass in the render graph uint32_t subpassIndex; @@ -79,8 +92,9 @@ namespace SHADE //! after we draw everything from the batch. Because of this, these draw calls //! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING //! COMPLEX. - std::vector&, uint32_t)>> exteriorDrawCalls; - /// For identifying subpasses + std::vector exteriorDrawCalls; + + // For identifying subpasses std::string name; @@ -88,7 +102,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - SHSubpass(const std::string& name, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept; + SHSubpass(const std::string& name, Handle inViewport, Handle inRenderer, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept; SHSubpass(SHSubpass&& rhs) noexcept; SHSubpass& operator=(SHSubpass&& rhs) noexcept; @@ -102,10 +116,10 @@ namespace SHADE void AddGeneralDepthOutput(std::string resourceToReference) noexcept; void AddInput(std::string resourceToReference) noexcept; void AddGeneralInput (std::string resourceToReference) noexcept; - void AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept; + void AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept; // Runtime functions - void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; + void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; void BindDescriptorInputDescriptorSets (Handle cmdBuffer, uint32_t frameIndex) const noexcept; From b84364ffe97d3725600e51266b48908526daea32 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 28 Dec 2022 12:43:40 +0800 Subject: [PATCH 12/24] Minor changes - Render Node Compute now has access to camera to send camera data to shaders - Fonts now have functions to bind descriptor set --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 1 + .../Graphics/MiddleEnd/TextRendering/SHFont.cpp | 5 +++++ .../src/Graphics/MiddleEnd/TextRendering/SHFont.h | 1 + .../TextRendering/SHTextRenderingSubSystem.cpp | 4 ++-- .../Graphics/RenderGraph/SHRenderGraphNode.cpp | 13 +++++++++---- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 15 ++++++++++++++- .../RenderGraph/SHRenderGraphNodeCompute.h | 8 ++++++-- 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 461b8783..43b05311 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -265,6 +265,7 @@ namespace SHADE auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout(); ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 }); + ssaoPass->SetRenderer (worldRenderer); // Add another pass to blur SSAO Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" }); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp index f0273940..b0d02b4c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp @@ -132,6 +132,11 @@ namespace SHADE } + void SHFont::BindDescriptorSet(Handle commandBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept + { + commandBuffer->BindDescriptorSet(descSet, SH_PIPELINE_TYPE::GRAPHICS, setIndex, {}); + } + std::unordered_map SHFont::GetUnicodeIndexing(void) const noexcept { return unicodeIndexing; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h index 1439281a..ff15cff0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h @@ -57,6 +57,7 @@ namespace SHADE SHFont (Handle inLogicalDeviceHdl, SHFontAsset const& asset) noexcept; void TransferToGPU (Handle commandBuffer) noexcept; void DoPostTransfer (Handle descPool, Handle layout) noexcept; + void BindDescriptorSet (Handle commandBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept; /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index f9afa48f..ab58b626 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -199,8 +199,8 @@ namespace SHADE renderer->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, cameraSetIndex, frameIndex); // bind descriptors for font (matrices) - cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, fontSetIndex, {}); - + fontHandle->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, fontSetIndex); + // bind VBO (position and indices) cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 1d8cea62..c23e19d7 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -353,14 +353,19 @@ namespace SHADE auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; - // Execute all subpass computes - for (auto& sbCompute : nodeComputes) + // We bind these 2 descriptor sets here because they apply to all node computes + if (!nodeComputes.empty()) { + // bind static global data + SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + // bind lighting data SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex); - - sbCompute->Execute(commandBuffer, frameIndex); } + + // Execute all subpass computes + for (auto& sbCompute : nodeComputes) + sbCompute->Execute(commandBuffer, frameIndex); } Handle SHRenderGraphNode::GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index ea574158..bb748913 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -10,6 +10,7 @@ #include "SHRenderGraphStorage.h" #include "SHRenderGraphResource.h" #include "Graphics/Commands/SHVkCommandBuffer.h" +#include "Graphics/MiddleEnd/Interface/SHRenderer.h" namespace SHADE { @@ -23,6 +24,7 @@ namespace SHADE , numWorkGroupScale {std::clamp(inNumWorkGroupScale, 0.0f, 1.0f)} , computeResource{} , name { std::move(nodeName) } + , renderer{ } { SHPipelineLayoutParams pipelineLayoutParams { @@ -94,14 +96,20 @@ namespace SHADE auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; - // bind descriptor sets + + // bind render graph resource cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {}); + // bind compute resource if (computeResource) { cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]); } + // bind camera data + if (renderer) + renderer->BindDescriptorSet (cmdBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + // dispatch compute cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1); @@ -187,6 +195,11 @@ namespace SHADE } } + void SHRenderGraphNodeCompute::SetRenderer(Handle inRenderer) noexcept + { + renderer = inRenderer; + } + void SHRenderGraphNodeCompute::ModifyWriteDescBufferComputeResource(uint32_t set, uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept { computeResource->descSet->ModifyWriteDescBuffer(set, binding, buffers, offset, range); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index a9a6ac68..cba37f80 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -7,6 +7,7 @@ #include #include #include +#include "Resource/SHHandle.h" namespace SHADE { @@ -19,6 +20,7 @@ namespace SHADE class SHVkShaderModule; class SHVkCommandBuffer; class SHVkBuffer; + class SHRenderer; class SHRenderGraphNodeCompute @@ -50,11 +52,12 @@ namespace SHADE //! Compute resources Handle computeResource; - //! - //! vector of resources needed by the subpass compute std::vector> resources; + //! For binding optional camera data to the post compute + Handle renderer; + //! X dimension work group size. Should scale with resource size. uint32_t groupSizeX; @@ -77,6 +80,7 @@ namespace SHADE void HandleResize (void) noexcept; void SetDynamicOffsets (std::span perFrameSizes) noexcept; + void SetRenderer (Handle inRenderer) noexcept; void ModifyWriteDescBufferComputeResource (uint32_t set, uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; void ModifyWriteDescImageComputeResource(uint32_t set, uint32_t binding, std::span const& viewSamplerLayouts) noexcept; From 99e7dbfa01ff11de6aae872c4ad7c3813385ceaa Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 28 Dec 2022 20:47:20 +0800 Subject: [PATCH 13/24] WIP --- Assets/Shaders/DebugDrawMesh_VS.glsl | 2 +- Assets/Shaders/DebugDrawMesh_VS.shshaderb | Bin 1853 -> 1761 bytes Assets/Shaders/DebugDraw_VS.glsl | 2 +- Assets/Shaders/DebugDraw_VS.shshaderb | Bin 1749 -> 1657 bytes Assets/Shaders/DeferredComposite_CS.glsl | 12 +- Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 5501 -> 5501 bytes Assets/Shaders/Kirsch_CS.glsl | 4 +- Assets/Shaders/Normals_FS.glsl | 2 +- Assets/Shaders/Normals_FS.shshaderb | Bin 2437 -> 2437 bytes Assets/Shaders/PureCopy_CS.glsl | 4 +- Assets/Shaders/PureCopy_CS.shshaderb | Bin 1273 -> 1273 bytes Assets/Shaders/SSAOBlur_CS.glsl | 4 +- Assets/Shaders/SSAOBlur_CS.shshaderb | Bin 4669 -> 4669 bytes Assets/Shaders/SSAO_CS.glsl | 12 +- Assets/Shaders/SSAO_CS.shshaderb | Bin 6141 -> 6141 bytes Assets/Shaders/TestCube_FS.glsl | 2 +- Assets/Shaders/TestCube_FS.shshaderb | Bin 2401 -> 2401 bytes Assets/Shaders/TestCube_Tile_FS.glsl | 2 +- Assets/Shaders/TestCube_Tile_FS.shshaderb | Bin 2185 -> 2185 bytes Assets/Shaders/TestCube_Tile_VS.glsl | 4 +- Assets/Shaders/TestCube_Tile_VS.shshaderb | Bin 4205 -> 4113 bytes Assets/Shaders/TestCube_VS.glsl | 2 +- Assets/Shaders/TestCube_VS.shshaderb | Bin 3781 -> 3689 bytes Assets/Shaders/Text_FS.glsl | 2 +- Assets/Shaders/Text_FS.shshaderb | Bin 2801 -> 2801 bytes Assets/Shaders/Text_VS.glsl | 4 +- Assets/Shaders/Text_VS.shshaderb | Bin 4921 -> 4813 bytes Assets/Shaders/ToSwapchain_FS.glsl | 2 +- Assets/Shaders/ToSwapchain_FS.shshaderb | Bin 881 -> 881 bytes Assets/Shaders/UI_FS.glsl | 2 +- Assets/Shaders/UI_FS.shshaderb | Bin 2285 -> 2285 bytes Assets/Shaders/UI_VS.glsl | 2 +- Assets/Shaders/UI_VS.shshaderb | Bin 3909 -> 3817 bytes .../MaterialInspector/SHMaterialInspector.cpp | 4 +- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 15 +-- .../GlobalData/SHGlobalDescriptorSets.cpp | 4 +- ...dData.cpp => SHGraphicsPredefinedData.cpp} | 79 +++++++----- ...finedData.h => SHGraphicsPredefinedData.h} | 40 ++++-- .../MiddleEnd/Interface/SHGraphicsConstants.h | 122 +++++++++--------- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 35 +++-- .../MiddleEnd/Interface/SHMaterial.cpp | 6 +- .../Interface/SHMaterialInstance.cpp | 14 +- .../Interface/SHPostOffscreenRenderSystem.cpp | 2 +- .../MiddleEnd/Interface/SHRenderer.cpp | 4 +- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 2 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 14 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 6 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.h | 2 +- .../MiddleEnd/TextRendering/SHFont.cpp | 11 +- .../Graphics/MiddleEnd/TextRendering/SHFont.h | 1 + .../SHTextRenderingSubSystem.cpp | 12 +- .../TextRendering/SHTextRenderingSubSystem.h | 1 + .../MiddleEnd/Textures/SHTextureLibrary.cpp | 9 +- .../Graphics/Pipeline/SHVkPipelineLayout.cpp | 4 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 17 ++- .../src/Graphics/RenderGraph/SHRenderGraph.h | 2 +- .../RenderGraph/SHRenderGraphNode.cpp | 10 +- .../Graphics/RenderGraph/SHRenderGraphNode.h | 2 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 48 ++++--- .../RenderGraph/SHRenderGraphNodeCompute.h | 4 +- .../RenderGraph/SHRenderGraphStorage.h | 2 +- .../SHRenderToSwapchainImageSystem.cpp | 4 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 19 ++- .../src/Graphics/RenderGraph/SHSubpass.h | 2 +- .../Serialization/SHSerializationHelper.hpp | 4 +- SHADE_Engine/src/Tools/SHEnumWrapper.h | 67 ++++++++++ .../src/Tools/Utilities/SHUtilities.h | 67 ---------- 67 files changed, 392 insertions(+), 307 deletions(-) rename SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/{SHPredefinedData.cpp => SHGraphicsPredefinedData.cpp} (67%) rename SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/{SHPredefinedData.h => SHGraphicsPredefinedData.h} (67%) create mode 100644 SHADE_Engine/src/Tools/SHEnumWrapper.h diff --git a/Assets/Shaders/DebugDrawMesh_VS.glsl b/Assets/Shaders/DebugDrawMesh_VS.glsl index 19c1a5b9..1f3b43ac 100644 --- a/Assets/Shaders/DebugDrawMesh_VS.glsl +++ b/Assets/Shaders/DebugDrawMesh_VS.glsl @@ -11,7 +11,7 @@ layout(location = 0) out struct vec4 Color; } Out; -layout(set = 2, binding = 0) uniform CameraData +layout(set = 1, binding = 0) uniform CameraData { vec4 position; mat4 vpMat; diff --git a/Assets/Shaders/DebugDrawMesh_VS.shshaderb b/Assets/Shaders/DebugDrawMesh_VS.shshaderb index 442cd789d87ff082d13ea456d7891105d3a27d52..c00e88f88b132792cb414c29188eba6b09c32e11 100644 GIT binary patch delta 57 zcmdnX_mG#F@dn#Q<{gZJtPFw-3=GUbTu_vs<(pWt`3>V##>qRGB^VhuUt*SJWMrHC MfkkvPC#wk)0JF>v?*IS* delta 141 zcmaFJyO)od(S&^?^A1Ksb_PKP1_ovzE=VmZE=Wx-$t+9tO)OzxU;{#s919TV7nNk> zgGCuOpJANJsOtd~hDovl6?ibP!uiTT{sm;Q$zjaOj7*!Wm}MEcA@;EYr3E(6V{v8z E000CPfdBvi diff --git a/Assets/Shaders/DebugDraw_VS.glsl b/Assets/Shaders/DebugDraw_VS.glsl index ce2dd544..dbfa7645 100644 --- a/Assets/Shaders/DebugDraw_VS.glsl +++ b/Assets/Shaders/DebugDraw_VS.glsl @@ -10,7 +10,7 @@ layout(location = 0) out struct vec4 vertColor; // location 0 } Out; -layout(set = 2, binding = 0) uniform CameraData +layout(set = 1, binding = 0) uniform CameraData { vec4 position; mat4 vpMat; diff --git a/Assets/Shaders/DebugDraw_VS.shshaderb b/Assets/Shaders/DebugDraw_VS.shshaderb index 9f5f7766a6fa15f0cfbb3fda364868075c99fad5..3ce6c3126f871cc084c827c69f936c92dae1cd4d 100644 GIT binary patch delta 58 zcmcc0`;&)>v0x+9Rz^Wq20;b}24)~GD9X?BO)S~`g0Yox@=|6AM#jzin0Xo5*}y8; KH(z7<&j{49q}WkXlq+keXbQS(fUXSi-=-2819v79h?qD#^$P zi!y9J!Pv^E>j4yoNwNYJcrdWS`N}~41!S?wPRz=TOqAgu_*Oi;cukX8a>m^_FNk_Q2hdQBjWEDz#?Y$DYpz03#y}egFUf delta 153 zcmeyX^;c`dMwWUO1_lOq1{MY>Agu_*Oi;cukX8a>m^_FNk_Q2hdQBjWEDz#?os8Qg$05NtMJ-OI?xGWi{wJR{3yKK6V*03^8$ga7~l diff --git a/Assets/Shaders/Kirsch_CS.glsl b/Assets/Shaders/Kirsch_CS.glsl index 3dec174d..8c60525a 100644 --- a/Assets/Shaders/Kirsch_CS.glsl +++ b/Assets/Shaders/Kirsch_CS.glsl @@ -50,8 +50,8 @@ #define NUM_MASKS 8 layout(local_size_x = 16, local_size_y = 16) in; -layout(set = 4, binding = 0, rgba8) uniform image2D inputImage; -layout(set = 4, binding = 1, rgba8) uniform image2D resultImage; +layout(set = 3, binding = 0, rgba8) uniform image2D inputImage; +layout(set = 3, binding = 1, rgba8) uniform image2D resultImage; const float kirsch[8][3][3] = { { diff --git a/Assets/Shaders/Normals_FS.glsl b/Assets/Shaders/Normals_FS.glsl index ba260d82..78b0a027 100644 --- a/Assets/Shaders/Normals_FS.glsl +++ b/Assets/Shaders/Normals_FS.glsl @@ -28,7 +28,7 @@ layout(location = 3) flat in struct } In2; layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global) -layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials +layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials { MatPropData data[]; } MatProp; diff --git a/Assets/Shaders/Normals_FS.shshaderb b/Assets/Shaders/Normals_FS.shshaderb index 7595ece992210bbf6849ea1b242415990e5f4c3b..7f72d16f3a00f591aa3e2d61c458d7716631b3f4 100644 GIT binary patch delta 14 VcmZn_ZWZ3($->CA*^9-R6#yP819AWW delta 14 VcmZn_ZWZ3($->CI*^9-R6#yPE19JcX diff --git a/Assets/Shaders/PureCopy_CS.glsl b/Assets/Shaders/PureCopy_CS.glsl index 89da6dd9..6f396199 100644 --- a/Assets/Shaders/PureCopy_CS.glsl +++ b/Assets/Shaders/PureCopy_CS.glsl @@ -46,8 +46,8 @@ layout(local_size_x = 16, local_size_y = 16) in; -layout(set = 4, binding = 0, rgba8) uniform image2D inputImage; -layout(set = 4, binding = 1, rgba8) uniform image2D targetImage; +layout(set = 3, binding = 0, rgba8) uniform image2D inputImage; +layout(set = 3, binding = 1, rgba8) uniform image2D targetImage; void main() diff --git a/Assets/Shaders/PureCopy_CS.shshaderb b/Assets/Shaders/PureCopy_CS.shshaderb index 30a629f5bcc0a56885e4bad78b8a2a3c41950982..158214301f698e895295f654f39b8802303d6ebc 100644 GIT binary patch delta 20 bcmey#`IB=)CL<&BZc3S}eVOkDx delta 47 zcmeyX|5txQE;A#`OG5a&JZq{SzXJ$4wHr{-I-BthqSWFEn diff --git a/Assets/Shaders/TestCube_FS.glsl b/Assets/Shaders/TestCube_FS.glsl index d6f88687..b6a1eab6 100644 --- a/Assets/Shaders/TestCube_FS.glsl +++ b/Assets/Shaders/TestCube_FS.glsl @@ -28,7 +28,7 @@ layout(location = 3) flat in struct } In2; layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global) -layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials +layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials { MatPropData data[]; } MatProp; diff --git a/Assets/Shaders/TestCube_FS.shshaderb b/Assets/Shaders/TestCube_FS.shshaderb index bcf5bf5ec1c14753c2ee4942289ea98261360a16..abd90cf744ad1b20429e7740fe4354edc390101c 100644 GIT binary patch delta 14 VcmaDT^iXJnCkrFfW-k_TRsbg=1Oxy8 delta 14 VcmaDT^iXJnCkrF=fMamzj}i^FQWp762$31uFmm delta 14 VcmeAa>=fMamzj}y^FQWp762$91uOsn diff --git a/Assets/Shaders/TestCube_Tile_VS.glsl b/Assets/Shaders/TestCube_Tile_VS.glsl index d27805ef..d3a1a0de 100644 --- a/Assets/Shaders/TestCube_Tile_VS.glsl +++ b/Assets/Shaders/TestCube_Tile_VS.glsl @@ -34,7 +34,7 @@ layout(location = 3) out struct } Out2; -layout(set = 2, binding = 0) uniform CameraData +layout(set = 1, binding = 0) uniform CameraData { vec4 position; mat4 vpMat; @@ -42,7 +42,7 @@ layout(set = 2, binding = 0) uniform CameraData mat4 projMat; } cameraData; -layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials +layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials { MatPropData data[]; } MatProp; diff --git a/Assets/Shaders/TestCube_Tile_VS.shshaderb b/Assets/Shaders/TestCube_Tile_VS.shshaderb index 9f83665663ad873e8c70d38c5227866e929b07d9..c7749607eeed6beb8fec3a36648f9e15387766c9 100644 GIT binary patch delta 64 zcmaE>Fj0Ytkz*s%OGZIf22}J&E%aYS22}j4yoNwNYJcrdWS`N}~41!S?w=U9{(nI?Z?+0Mwkc@--w6C?ZN4eX+u J53&bv006Fj8uq`%;F9F<~RqOGZIf22}>j4yoNwNYJcrdWS`N}~41!S?wZY;`-Oq;Vy3 C{up`y diff --git a/Assets/Shaders/Text_FS.glsl b/Assets/Shaders/Text_FS.glsl index fdf32583..36bdb8eb 100644 --- a/Assets/Shaders/Text_FS.glsl +++ b/Assets/Shaders/Text_FS.glsl @@ -28,7 +28,7 @@ layout(location = 3) flat in struct -layout(set = 4, binding = 0) uniform sampler2D fontBitmap; +layout(set = 2, binding = 0) uniform sampler2D fontBitmap; layout(location = 0) out vec4 color; layout(location = 1) out uint outEntityID; diff --git a/Assets/Shaders/Text_FS.shshaderb b/Assets/Shaders/Text_FS.shshaderb index d9b47d6ee781fc9da896109c90deb842550c2a77..024073a8ae8ef98827d7d1b01cf002338151d30a 100644 GIT binary patch delta 14 Vcmew;`cZVlLncP1&5xM)IRG%91yKM1 delta 14 Vcmew;`cZVlLncO+&5xM)IRG%L1ycY3 diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index 0498ae39..1e05dd25 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -25,7 +25,7 @@ layout(location = 3) out struct } Out2; // Camera data -layout(set = 2, binding = 0) uniform CameraData +layout(set = 1, binding = 0) uniform CameraData { vec4 position; mat4 vpMat; @@ -43,7 +43,7 @@ layout(std140, push_constant) uniform TestPushConstant } testPushConstant; // Descriptor sets -layout(std430, set = 4, binding = 1) buffer GlyphTransforms +layout(std430, set = 2, binding = 1) buffer GlyphTransforms { mat4 matrices[]; } glyphTransforms; diff --git a/Assets/Shaders/Text_VS.shshaderb b/Assets/Shaders/Text_VS.shshaderb index 25eff84a998699690af58db696ddca8c8bc20864..527b3db78c0c72f55812d5231faa7654e421e5b4 100644 GIT binary patch delta 317 zcmdm~c2-r4@rV!u7%(#_vokO-GH@~QGA!OG_LW(Xm0=1{h8c(pit@936H7MRurM+* zGHteFjb@yDkxhb;aq}xSRu)FK$sf2xCv$QuuqrUHFf80`$9qOTSi$nMfNYQ&kT^(w&W zAr{3j4=Tt6qyre(8MJ`(d>{rH0MY=Gmj>dAK!ZVY3xF8p0FW9-px8nny$FaW1FS6ov2PS0W-Jc2f}{RL~&m11N}_ZYm0{bR`ndjV(2}b??qb{I|B%7m!)` z5Q6vuK81U~ThnU7H+RlCH+P1-SKj7IW_eQjkL$#th>=Lfd~VwH5zh$A2$B4r1fjR^WT1 zzsD{RCwV(sno1Znj=BataF(@aKcg@I>;`#NM61{d`&&?dpzql4K#TJ=zX$D6UwbOl z2iSyddPb;^g-02B?ZPvE-mW|qrbFG5Q1sRv&;j~^=4H5Gux4G*3v^%|uSb1`9Ohw- M->tf9&nGs_4-?-vp8x;= diff --git a/Assets/Shaders/ToSwapchain_FS.glsl b/Assets/Shaders/ToSwapchain_FS.glsl index a68fa0c7..3cf1752f 100644 --- a/Assets/Shaders/ToSwapchain_FS.glsl +++ b/Assets/Shaders/ToSwapchain_FS.glsl @@ -3,7 +3,7 @@ #extension GL_ARB_shading_language_420pack : enable #extension GL_EXT_nonuniform_qualifier : require -layout (input_attachment_index = 0, set = 4, binding = 0) uniform subpassInput sceneTexture; +layout (input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput sceneTexture; layout(location = 0) out vec4 fragColor; diff --git a/Assets/Shaders/ToSwapchain_FS.shshaderb b/Assets/Shaders/ToSwapchain_FS.shshaderb index b10a9d6cc18532c8501c040dbbba8899a7e9af1a..0bee0ac67036b416f1ad7249d12b6e7ea411b98d 100644 GIT binary patch delta 14 Vcmey!_K|HvCnF=n<}SwPi~uZA1yBG0 delta 14 Vcmey!_K|HvCnF=v<}SwPi~uZY1yle4 diff --git a/Assets/Shaders/UI_FS.glsl b/Assets/Shaders/UI_FS.glsl index 093cc9c6..0c4c526c 100644 --- a/Assets/Shaders/UI_FS.glsl +++ b/Assets/Shaders/UI_FS.glsl @@ -28,7 +28,7 @@ layout(location = 3) flat in struct } In2; layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global) -layout (std430, set = 3, binding = 0) buffer MaterialProperties // For materials +layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials { MatPropData data[]; } MatProp; diff --git a/Assets/Shaders/UI_FS.shshaderb b/Assets/Shaders/UI_FS.shshaderb index fcb72b6e912e98ddd75e1e9eb888bad2282d0f97..703040e1a63c9c59d398cc68a6df7121a76c6b39 100644 GIT binary patch delta 14 VcmaDW_*QU(CkrFfW-pe-EC4B41f>7~ delta 14 VcmaDW_*QU(CkrFq_fnRb@d4jP<`;~DtPH9Q3=GUbTu_vs<(pWtS%xW;Y4S=I2}Z`vhge*h*xA4; S6gLa8A7^A_-h7KAn+*Uc>JP^N delta 142 zcmaDUdsL2@(T0B`^9x2pb_P`j1_ovzE=VmZE=Wx-$t+9tO)OzxU;{#s919TV7nNk> zgGCuO|6vSe()9oe!z5XO3OpEC;e2Hv{{phuWH%ONMyAbKEUrw9?2|XJiEci~wuh0C KWpf=zHX8twl^MwZ diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp index 9dbb9542..ddcef902 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -196,10 +196,12 @@ namespace SHADE if (!fragShader) return; + auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); + // Get interface for the shader combination auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + mappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA ); if (!interface) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index c92ad808..ab36a7b4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -25,7 +25,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "ECS_Base/Managers/SHComponentManager.h" #include "Math/Transform/SHTransformComponent.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Scene/SHSceneManager.h" #include "UI/SHUIComponent.h" @@ -411,12 +411,12 @@ namespace SHADE instancedIntegerData.reserve(numTotalElements); instancedIntegerData.clear(); - auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); // - Material Properties Data const Handle SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + descMappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, vk::ShaderStageFlagBits::eFragment ); @@ -571,14 +571,14 @@ namespace SHADE cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0); if (matPropsDescSet[frameIndex]) { - auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); cmdBuffer->BindDescriptorSet ( matPropsDescSet[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, - descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + descMappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), dynamicOffset ); } @@ -611,7 +611,7 @@ namespace SHADE { matPropsDescSet[frameIndex] = descPool->Allocate ( - SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS), + SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS), { 0 } ); #ifdef _DEBUG @@ -623,8 +623,7 @@ namespace SHADE #endif } - auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; - uint32_t const MATERIAL_DESC_SET_INDEX = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS); + static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0; std::array, 1> bufferList = { matPropsBuffer[frameIndex] }; matPropsDescSet[frameIndex]->ModifyWriteDescBuffer diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp index 09dbef51..9e1263cf 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp @@ -23,8 +23,8 @@ namespace SHADE void SHGlobalDescriptorSets::BindStaticGlobalData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex) noexcept { // Bind descriptor set for static global data - static constexpr std::array TEX_DYNAMIC_OFFSET{ 0 }; - cmdBuffer->BindDescriptorSet(staticGlobalDataDescriptorSet, pipelineType, setIndex, const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); + static std::array TEX_DYNAMIC_OFFSET{ 0 }; + cmdBuffer->BindDescriptorSet(staticGlobalDataDescriptorSet, pipelineType, setIndex, std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); } /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp similarity index 67% rename from SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp rename to SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index ac7ab982..36566108 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -1,5 +1,5 @@ #include "SHpch.h" -#include "SHPredefinedData.h" +#include "SHGraphicsPredefinedData.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h" @@ -11,29 +11,32 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Static Definitions */ /*-----------------------------------------------------------------------------------*/ - std::vector> SHPredefinedData::predefinedLayouts; - SHVertexInputState SHPredefinedData::defaultVertexInputState; - SHPredefinedData::PerSystem SHPredefinedData::batchingSystemData; - SHPredefinedData::PerSystem SHPredefinedData::textSystemData; - SHPredefinedData::PerSystem SHPredefinedData::renderGraphNodeComputeData; + std::vector> SHGraphicsPredefinedData::predefinedLayouts; + SHVertexInputState SHGraphicsPredefinedData::defaultVertexInputState; + std::vector SHGraphicsPredefinedData::perSystemData; - void SHPredefinedData::InitDescMappings(void) noexcept + //SHGraphicsPredefinedData::PerSystem SHGraphicsPredefinedData::batchingSystemData; + //SHGraphicsPredefinedData::PerSystem SHGraphicsPredefinedData::textSystemData; + //SHGraphicsPredefinedData::PerSystem SHGraphicsPredefinedData::renderGraphNodeComputeData; + + void SHGraphicsPredefinedData::InitDescMappings(void) noexcept { - batchingSystemData.descMappings.AddMappings + + perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descMappings.AddMappings ({ {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1}, {SHGraphicsConstants::DescriptorSetTypes::MATERIALS, 2}, }); - textSystemData.descMappings.AddMappings + perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings ({ {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1}, {SHGraphicsConstants::DescriptorSetTypes::FONT, 2}, }); - renderGraphNodeComputeData.descMappings.AddMappings + perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descMappings.AddMappings ({ {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, {SHGraphicsConstants::DescriptorSetTypes::LIGHTS, 1}, @@ -43,16 +46,17 @@ namespace SHADE }); } - void SHPredefinedData::InitDummyPipelineLayouts(Handle logicalDevice) noexcept + void SHGraphicsPredefinedData::InitDummyPipelineLayouts(Handle logicalDevice) noexcept { - batchingSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ batchingSystemData.descSetLayouts }); - textSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ textSystemData.descSetLayouts }); + perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts }); + perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts }); + perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descSetLayouts }); } /*-----------------------------------------------------------------------------------*/ /* Function Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHPredefinedData::InitDescSetLayouts(Handle logicalDevice) noexcept + void SHGraphicsPredefinedData::InitDescSetLayouts(Handle logicalDevice) noexcept { SHVkDescriptorSetLayout::Binding genericDataBinding { @@ -153,22 +157,29 @@ namespace SHADE predefinedLayouts.push_back(materialDataPerInstanceLayout); predefinedLayouts.push_back(fontDataDescSetLayout); - batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts + perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts ( SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS ); - textSystemData.descSetLayouts = GetPredefinedDescSetLayouts + perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts ( SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT ); + + perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descSetLayouts = GetPredefinedDescSetLayouts + ( + SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS + ); } - void SHPredefinedData::InitDefaultVertexInputState(void) noexcept + void SHGraphicsPredefinedData::InitDefaultVertexInputState(void) noexcept { defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 @@ -178,15 +189,16 @@ namespace SHADE defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8 } - void SHPredefinedData::Init(Handle logicalDevice) noexcept + void SHGraphicsPredefinedData::Init(Handle logicalDevice) noexcept { + perSystemData.resize(SHUtilities::ConvertEnum(SystemType::NUM_TYPES)); InitDescSetLayouts(logicalDevice); InitDefaultVertexInputState(); InitDescMappings(); InitDummyPipelineLayouts (logicalDevice); } - std::vector> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept + std::vector> SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept { std::vector> layoutsFound; for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i) @@ -198,26 +210,35 @@ namespace SHADE return layoutsFound; } - - SHVertexInputState const& SHPredefinedData::GetDefaultViState(void) noexcept + SHVertexInputState const& SHGraphicsPredefinedData::GetDefaultViState(void) noexcept { return defaultVertexInputState; } - SHPredefinedData::PerSystem const& SHPredefinedData::GetBatchingSystemData(void) noexcept + SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetSystemData(SystemType systemType) noexcept { - return batchingSystemData; + return perSystemData[static_cast(systemType)]; } - SHPredefinedData::PerSystem const& SHPredefinedData::GetTextSystemData(void) noexcept + SHDescriptorMappings::MapType const& SHGraphicsPredefinedData::GetMappings(SystemType systemType) noexcept { - return textSystemData; + return perSystemData[static_cast(systemType)].descMappings.GetMappings(); } - SHPredefinedData::PerSystem const& SHPredefinedData::GetRenderGraphNodeComputeData(void) noexcept - { - return renderGraphNodeComputeData; - } + //SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetBatchingSystemData(void) noexcept + //{ + // return batchingSystemData; + //} + + //SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetTextSystemData(void) noexcept + //{ + // return textSystemData; + //} + + //SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetRenderGraphNodeComputeData(void) noexcept + //{ + // return renderGraphNodeComputeData; + //} } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h similarity index 67% rename from SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h rename to SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index b19a1e0b..ac10093a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -5,6 +5,8 @@ #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h" #include "Tools/Utilities/SHUtilities.h" +#include "Tools/SHEnumWrapper.h" +#include namespace SHADE { @@ -13,17 +15,24 @@ namespace SHADE class SHVkDescriptorSetGroup; class SHVkPipelineLayout; - - class SH_API SHPredefinedData + class SH_API SHGraphicsPredefinedData { public: + enum class SystemType + { + BATCHING = 0, + TEXT_RENDERING, + RENDER_GRAPH_NODE_COMPUTE, + NUM_TYPES + }; + struct PerSystem { //! vector of descriptor set layouts used by a system std::vector> descSetLayouts; //! pipeline layout used for binding descriptor sets in the system - static Handle dummyPipelineLayout; + Handle dummyPipelineLayout; //! Descriptor type mappings for the system SHDescriptorMappings descMappings; @@ -36,14 +45,17 @@ namespace SHADE //! Default vertex input state (used by everything). static SHVertexInputState defaultVertexInputState; - //! predefined data for the batching system - static PerSystem batchingSystemData; + //! Predefined data for each type of system + static std::vector perSystemData; - //! predefined data for the text system - static PerSystem textSystemData; + ////! predefined data for the batching system + //static PerSystem batchingSystemData; - //! predefined data for the render graph node computes - static PerSystem renderGraphNodeComputeData; + ////! predefined data for the text system + //static PerSystem textSystemData; + + ////! predefined data for the render graph node computes + //static PerSystem renderGraphNodeComputeData; static void InitDescMappings (void) noexcept; static void InitDummyPipelineLayouts (Handle logicalDevice) noexcept; @@ -54,7 +66,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* Constructors */ /*-----------------------------------------------------------------------*/ - SHPredefinedData() = delete; + SHGraphicsPredefinedData() = delete; /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ @@ -66,8 +78,10 @@ namespace SHADE /*-----------------------------------------------------------------------*/ static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; static SHVertexInputState const& GetDefaultViState (void) noexcept; - static PerSystem const& GetBatchingSystemData(void) noexcept; - static PerSystem const& GetTextSystemData(void) noexcept; - static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept; + static PerSystem const& GetSystemData (SystemType systemType) noexcept; + static SHDescriptorMappings::MapType const& GetMappings (SystemType systemType) noexcept; + //static PerSystem const& GetBatchingSystemData(void) noexcept; + //static PerSystem const& GetTextSystemData(void) noexcept; + //static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 06ffe381..86742b53 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -58,68 +58,68 @@ namespace SHADE static constexpr uint32_t EDITOR = 0; }; - struct DescriptorSetIndex - { - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for static global values like generic data, and - texture samplers - */ - /***************************************************************************/ - static constexpr uint32_t STATIC_GLOBALS = 0; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for dynamic global values like lights. - */ - /***************************************************************************/ - static constexpr uint32_t DYNAMIC_GLOBALS = 1; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for high frequency changing global values like - camera matrices. - */ - /***************************************************************************/ - static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for per-instance/material changing values. - */ - /***************************************************************************/ - static constexpr uint32_t PER_INSTANCE = 3; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for render graph resources. Unlike the sets from - 1 to 3 and 6, this set index does not have hard coded bindings and is - NOT part of the layouts included in the global data. - */ - /***************************************************************************/ - static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; - /***************************************************************************/ - /*! - \brief - DescriptorSet Index for render graph node compute resources. For data - that we wish to pass to compute shaders in the render graph, this is - the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have - hard coded bindings and is NOT part of the layouts included in the global - data. - */ - /***************************************************************************/ - static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; + //struct DescriptorSetIndex + //{ + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for static global values like generic data, and + // texture samplers + // */ + // /***************************************************************************/ + // static constexpr uint32_t STATIC_GLOBALS = 0; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for dynamic global values like lights. + // */ + // /***************************************************************************/ + // static constexpr uint32_t DYNAMIC_GLOBALS = 1; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for high frequency changing global values like + // camera matrices. + // */ + // /***************************************************************************/ + // static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for per-instance/material changing values. + // */ + // /***************************************************************************/ + // static constexpr uint32_t PER_INSTANCE = 3; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for render graph resources. Unlike the sets from + // 1 to 3 and 6, this set index does not have hard coded bindings and is + // NOT part of the layouts included in the global data. + // */ + // /***************************************************************************/ + // static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; + // /***************************************************************************/ + // /*! + // \brief + // DescriptorSet Index for render graph node compute resources. For data + // that we wish to pass to compute shaders in the render graph, this is + // the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have + // hard coded bindings and is NOT part of the layouts included in the global + // data. + // */ + // /***************************************************************************/ + // static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5; - /***************************************************************************/ - /*! - \brief - To store font data. - - */ - /***************************************************************************/ - static constexpr uint32_t FONT_DATA = 4; - }; + // /***************************************************************************/ + // /*! + // \brief + // To store font data. + // + // */ + // /***************************************************************************/ + // static constexpr uint32_t FONT_DATA = 4; + //}; struct DescriptorSetBindings { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 43b05311..b531e707 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -31,7 +31,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" #include "SHGraphicsConstants.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" #include "Assets/Asset Types/SHTextureAsset.h" @@ -127,6 +127,22 @@ namespace SHADE SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_VS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDrawMesh_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/Normals_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_Tile_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_Tile_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_VS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false); // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); @@ -207,7 +223,7 @@ namespace SHADE renderGraph->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); renderGraph->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); renderGraph->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); - renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second, vk::Format::eR8Unorm); + renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); /*-----------------------------------------------------------------------*/ @@ -261,10 +277,10 @@ namespace SHADE // Add the pass to generate an image with just SSAO data Handle ssaoPass = gBufferNode->AddNodeCompute("SSAO", ssaoShader, { "Position", "Normals", "SSAO" }); auto ssaoDataBuffer = ssaoStorage->GetBuffer(); - ssaoPass->ModifyWriteDescBufferComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_BUFFER_BINDING, { &ssaoDataBuffer, 1 }, 0, ssaoStorage->GetBuffer()->GetSizeStored()); + ssaoPass->ModifyWriteDescBufferComputeResource(SHSSAO::DESC_SET_BUFFER_BINDING, { &ssaoDataBuffer, 1 }, 0, ssaoStorage->GetBuffer()->GetSizeStored()); auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout(); - ssaoPass->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 }); + ssaoPass->ModifyWriteDescImageComputeResource(SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 }); ssaoPass->SetRenderer (worldRenderer); // Add another pass to blur SSAO @@ -392,7 +408,7 @@ namespace SHADE void SHGraphicsSystem::InitMiddleEnd(void) noexcept { - SHPredefinedData::Init(device); + SHGraphicsPredefinedData::Init(device); InitRenderGraph(); @@ -435,7 +451,6 @@ namespace SHADE auto uiNode = renderGraph->GetNode("Screen Space Pass"); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); - SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(texLibrary.GetTextureDescriptorSetGroup()); SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); } @@ -844,7 +859,7 @@ namespace SHADE } // Create the renderer - auto renderer = resourceManager.Create(device, swapchain->GetNumImages(), renderContextCmdPools, descPool); + auto renderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, projectionType); // Store renderers.emplace_back(renderer); @@ -989,6 +1004,8 @@ namespace SHADE ); device->WaitIdle(); graphicsTexCmdBuffer.Free(); graphicsTexCmdBuffer = {}; + SHGlobalDescriptorSets::SetStaticGlobalDataDescriptorSet(texLibrary.GetTextureDescriptorSetGroup()); + } Handle SHGraphicsSystem::GetTextureHandle(SHTexture::Index textureId) const @@ -1006,7 +1023,7 @@ namespace SHADE void SHGraphicsSystem::BuildFonts(void) noexcept { - fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); + fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); } #pragma endregion ADD_REMOVE @@ -1245,7 +1262,7 @@ namespace SHADE device, SHPipelineLayoutParams { .shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader }, - .predefinedDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA) + .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts } ); auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp index 1a007b95..8e7dbd0f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp @@ -9,6 +9,8 @@ #include "ECS_Base/Managers/SHSystemManager.h" #include "SHGraphicsSystem.h" #include "SHMaterialInstance.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" + namespace SHADE { @@ -95,9 +97,11 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ Handle SHMaterial::GetShaderBlockInterface() const noexcept { + auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); return pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + mappings.at (SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, vk::ShaderStageFlagBits::eFragment ); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp index 7526538f..6a1f235e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp @@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited. #include "SHMaterial.h" #include "Graphics/Pipeline/SHVkPipeline.h" #include "Tools/Logger/SHLogger.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" namespace SHADE { @@ -78,11 +79,12 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ Handle SHMaterialInstance::getShaderBlockInterface() const noexcept { - return baseMaterial->GetPipeline()->GetPipelineLayout()->GetShaderBlockInterface - ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, - SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, - vk::ShaderStageFlagBits::eFragment - ); + return baseMaterial->GetPipeline()->GetPipelineLayout()->GetShaderBlockInterface + ( + SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, + vk::ShaderStageFlagBits::eFragment + ); } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.cpp index 8b41a979..dd3b4366 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.cpp @@ -56,7 +56,7 @@ namespace SHADE }; // Create descriptor set layout - offscreenRenderDescSetLayout = logicalDevice->CreateDescriptorSetLayout(0, { imageBinding }, false); + offscreenRenderDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ imageBinding }, false); // Create descriptor set offscreenRenderDescSet = descriptorPool->Allocate({ offscreenRenderDescSetLayout }, { 1 }); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index be9f0482..b1508ce7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -21,7 +21,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Camera/SHCameraDirector.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" namespace SHADE { @@ -36,7 +36,7 @@ namespace SHADE //for (uint32_t i = 0; i < commandBuffers.size(); ++i) // commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); - cameraDescriptorSet = descriptorPool->Allocate(SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA), { 1 }); + cameraDescriptorSet = descriptorPool->Allocate(SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA), { 1 }); #ifdef _DEBUG const auto& CAM_DESC_SETS = cameraDescriptorSet->GetVkHandle(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index c93050d7..baf76187 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -36,7 +36,7 @@ namespace SHADE class SHVkCommandBuffer; class SHCamera; class SHVkDescriptorSetGroup; - class SHPredefinedData; + class SHGraphicsPredefinedData; class SHVkDescriptorPool; class SHVkBuffer; class SHCameraDirector; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index abbf88c3..93e80cb0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -1,6 +1,6 @@ #include "SHpch.h" #include "SHLightingSubSystem.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Tools/Utilities/SHUtilities.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Buffers/SHVkBuffer.h" @@ -320,15 +320,16 @@ namespace SHADE void SHLightingSubSystem::UpdateDescSet(uint32_t binding) noexcept { auto buffer = perTypeData[binding].GetDataBuffer(); + static constexpr uint32_t LIGHTING_DATA_SET_INDEX = 0; // We bind the buffer with the correct desc set binding - lightingDataDescSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, + lightingDataDescSet->ModifyWriteDescBuffer(LIGHTING_DATA_SET_INDEX, binding + 1, // we want to +1 here because the first binding is reserved for count { &buffer, 1 }, 0, perTypeData[binding].GetDataSize() * perTypeData[binding].GetMaxLights()); - lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, binding + 1); // +1 here, same reason. see above + lightingDataDescSet->UpdateDescriptorSetBuffer(LIGHTING_DATA_SET_INDEX, binding + 1); // +1 here, same reason. see above } /***************************************************************************/ @@ -385,7 +386,7 @@ namespace SHADE std::fill (variableSizes.begin(), variableSizes.end(), 1); // Create the descriptor set - lightingDataDescSet = descPool->Allocate({ SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS) }, variableSizes); + lightingDataDescSet = descPool->Allocate({ SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS) }, variableSizes); #ifdef _DEBUG const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle(); for (int i = 0; i < static_cast(CAM_DESC_SETS.size()); ++i) @@ -408,8 +409,9 @@ namespace SHADE // Create the GPU buffer to hold light count lightCountsBuffer = logicalDevice->CreateBuffer(lightCountsAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightCountsAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eUniformBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, "Light Count Data"); - lightingDataDescSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT, {&lightCountsBuffer, 1}, 0, sizeof (uint32_t) * NUM_LIGHT_TYPES); - lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT); + static constexpr uint32_t LIGHTING_DATA_SET_INDEX = 0; + lightingDataDescSet->ModifyWriteDescBuffer(LIGHTING_DATA_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT, { &lightCountsBuffer, 1 }, 0, sizeof(uint32_t) * NUM_LIGHT_TYPES); + lightingDataDescSet->UpdateDescriptorSetBuffer(LIGHTING_DATA_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT); for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 9b16a279..baf09a2d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -1,7 +1,7 @@ #include "SHpch.h" #include "SHPipelineLibrary.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/SHVkUtil.h" @@ -13,7 +13,7 @@ namespace SHADE SHPipelineLayoutParams params { .shaderModules = {vsFsPair.first, vsFsPair.second}, - .globalDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts + .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts }; // Create the pipeline layout @@ -21,7 +21,7 @@ namespace SHADE // Create the pipeline and configure the default vertex input state auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass); - newPipeline->GetPipelineState().SetVertexInputState(SHPredefinedData::GetDefaultViState()); + newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsPredefinedData::GetDefaultViState()); SHColorBlendState colorBlendState{}; colorBlendState.logic_op_enable = VK_FALSE; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h index 389f5fa8..5085f21f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h @@ -10,7 +10,7 @@ namespace SHADE class SHVkDescriptorSetLayouts; class SHVkPipeline; class SHSubpass; - class SHPredefinedData; + class SHGraphicsPredefinedData; // Pipeline library is a PURELY MIDDLE END SYSTEM. It is responsible for only creating pipelines from shaders and caching // them so that they don't need to be recreated again. diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp index b0d02b4c..b6ec5f83 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp @@ -1,7 +1,7 @@ #include "SHpch.h" #include "SHFont.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" @@ -121,14 +121,15 @@ namespace SHADE descSet = descPool->Allocate({ layout }, { 1 }); auto viewLayoutSampler = std::make_tuple(bitmapDataImageView, sampler, vk::ImageLayout::eShaderReadOnlyOptimal); - descSet->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, {&viewLayoutSampler, 1}); + static constexpr uint32_t FONT_DATA_SET_INDEX = 0; + descSet->ModifyWriteDescImage(FONT_DATA_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, {&viewLayoutSampler, 1}); - descSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, + descSet->ModifyWriteDescBuffer(FONT_DATA_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, { &matrixDataBuffer, 1 }, 0, fontAsset.glyphTransformations.size() * sizeof(SHMatrix)); // Bind image and buffer to desc set. - descSet->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA); - descSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA); + descSet->UpdateDescriptorSetImages(FONT_DATA_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA); + descSet->UpdateDescriptorSetBuffer(FONT_DATA_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h index ff15cff0..b3731af9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h @@ -3,6 +3,7 @@ #include "Resource/SHHandle.h" #include "msdf-atlas-gen/msdf-atlas-gen.h" #include "Assets/Asset Types/SHFontAsset.h" +#include "Graphics/Pipeline/SHPipelineType.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index ab58b626..3a0110a4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -6,7 +6,7 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/TextRendering/SHFont.h" #include "Graphics/Buffers/SHVkBuffer.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/SHVkUtil.h" #include "Graphics/RenderGraph/SHSubpass.h" @@ -103,7 +103,7 @@ namespace SHADE SHPipelineLayoutParams plParams { .shaderModules = {textVS, textFS}, - .predefinedDescSetLayouts = SHPredefinedData::GetTextSystemData().descSetLayouts + .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::TEXT_RENDERING).descSetLayouts }; pipelineLayout = logicalDevice->CreatePipelineLayout(plParams); @@ -177,10 +177,10 @@ namespace SHADE void SHTextRenderingSubSystem::Render(Handle cmdBuffer, Handle renderer, uint32_t frameIndex) noexcept { auto& textRendererComps = SHComponentManager::GetDense(); - auto const& mappings = SHPredefinedData::GetTextSystemData().descMappings; - uint32_t fontSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::FONT); - uint32_t staticGlobalSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA); - uint32_t cameraSetIndex = mappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA); + auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::TEXT_RENDERING); + uint32_t fontSetIndex = mappings.at(SHGraphicsConstants::DescriptorSetTypes::FONT); + uint32_t staticGlobalSetIndex = mappings.at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA); + uint32_t cameraSetIndex = mappings.at(SHGraphicsConstants::DescriptorSetTypes::CAMERA); for (auto& comp : textRendererComps) { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index c9a89129..c91e7794 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -20,6 +20,7 @@ namespace SHADE class SHVkRenderpass; class SHSubpass; class SHVkShaderModule; + class SHRenderer; class SHTextRenderingSubSystem { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index a31f54de..9df14eba 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -24,7 +24,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Images/SHVkImage.h" #include "Graphics/Images/SHVkImageView.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Assets/Asset Types/SHTextureAsset.h" namespace SHADE @@ -168,22 +168,23 @@ namespace SHADE } texDescriptors = descPool->Allocate ( - { SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] }, + { SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA) }, { static_cast(texOrder.size()) } ); #ifdef _DEBUG for (auto set : texDescriptors->GetVkHandle()) SET_VK_OBJ_NAME(device, vk::ObjectType::eDescriptorSet, set, "[Descriptor Set] Static Globals"); #endif + static constexpr uint32_t TEX_DESCRIPTOR_SET_INDEX = 0; texDescriptors->ModifyWriteDescImage ( - SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS, + TEX_DESCRIPTOR_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::IMAGE_AND_SAMPLERS_DATA, combinedImageSamplers ); texDescriptors->UpdateDescriptorSetImages ( - SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS, + TEX_DESCRIPTOR_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::IMAGE_AND_SAMPLERS_DATA ); } diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp index 0333aa09..c2d83052 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp @@ -220,7 +220,7 @@ namespace SHADE // 1 descriptor set layout for every descriptor set detected. for (auto const& set : setsWithBindings) { - auto newDescriptorSetLayout = logicalDeviceHdl->CreateDescriptorSetLayout(set.first, set.second); + auto newDescriptorSetLayout = logicalDeviceHdl->CreateDescriptorSetLayout(set.second); descriptorSetLayoutsAllocate.push_back(newDescriptorSetLayout); } @@ -317,7 +317,7 @@ namespace SHADE , logicalDeviceHdl {inLogicalDeviceHdl} , pushConstantInterface{} , vkPcRanges{} - , descriptorSetLayoutsGlobal{pipelineLayoutParams.globalDescSetLayouts } // do a copy, some other pipeline layout might need this + , descriptorSetLayoutsGlobal{pipelineLayoutParams.predefinedDescSetLayouts } // do a copy, some other pipeline layout might need this , descriptorSetLayoutsAllocate{} , vkDescriptorSetLayoutsAllocate{} , descriptorSetLayoutsPipeline{} diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index d431cf47..a24f8968 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -12,7 +12,7 @@ #include "SHRenderGraphStorage.h" #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "Tools/Utilities/SHUtilities.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h" #include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" @@ -578,7 +578,8 @@ namespace SHADE uint32_t h = static_cast(resource->GetHeight()); cmdBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); - newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex); + static constexpr uint32_t INPUT_IMAGE_SET_INDEX = 0; + newSubpass->BindInputDescriptorSets (cmdBuffer, INPUT_IMAGE_SET_INDEX, frameIndex); // draw a quad. cmdBuffer->DrawArrays(4, 1, 0, 0); @@ -634,16 +635,18 @@ namespace SHADE auto cmdBuffer = commandBuffers[frameIndex]; cmdBuffer->BeginLabeledSegment(name); - // Force bind pipeline layout - cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::GRAPHICS); - cmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetBatchingSystemData().dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); + auto batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING); - auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + // Force bind pipeline layout + cmdBuffer->ForceSetPipelineLayout(batchingSystemData.dummyPipelineLayout, SH_PIPELINE_TYPE::GRAPHICS); + cmdBuffer->ForceSetPipelineLayout(batchingSystemData.dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); + + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); for (auto& node : nodes) { // bind static global data - SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); node->Execute(cmdBuffer, descPool, frameIndex); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index c69e83b1..948fd9f7 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -29,7 +29,7 @@ namespace SHADE class SHVkCommandPool; class SHVkCommandBuffer; class SHRenderGraphNode; - class SHPredefinedData; + class SHGraphicsPredefinedData; class SHVkDescriptorPool; class SHRenderGraphStorage; class SHRenderToSwapchainImageSystem; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index c23e19d7..01363e6b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -10,7 +10,7 @@ #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "Graphics/SHVkUtil.h" #include "Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" namespace SHADE { @@ -351,16 +351,18 @@ namespace SHADE commandBuffer->EndRenderpass(); - auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE); // We bind these 2 descriptor sets here because they apply to all node computes if (!nodeComputes.empty()) { + commandBuffer->ForceSetPipelineLayout(SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); + // bind static global data - SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); // bind lighting data - SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex); + SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex); } // Execute all subpass computes diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index f7e55d4a..ebaf48e2 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -19,7 +19,7 @@ namespace SHADE class SHVkLogicalDevice; class SHVkRenderpass; class SHVkDescriptorPool; - class SHPredefinedData; + class SHGraphicsPredefinedData; class SHRenderGraphStorage; class SHRenderGraphNodeCompute; class SHRenderer; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index bb748913..c295d93b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -6,7 +6,7 @@ #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "SHRenderGraphStorage.h" #include "SHRenderGraphResource.h" #include "Graphics/Commands/SHVkCommandBuffer.h" @@ -29,7 +29,7 @@ namespace SHADE SHPipelineLayoutParams pipelineLayoutParams { .shaderModules = {computeShaderModule}, - .predefinedDescSetLayouts = SHPredefinedData::GetRenderGraphNodeComputeData().descSetLayouts, + .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).descSetLayouts, .dynamicBufferBindings = std::move(dynamicBufferBindings), }; @@ -47,13 +47,13 @@ namespace SHADE // save the resources resources = std::move (subpassComputeResources); - auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE); auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline(); //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 = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE)]; + auto const& graphResourceLayout = layouts[descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE)]; // Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE) for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) @@ -66,11 +66,11 @@ namespace SHADE } // check if all layouts are there - if (layouts.size() == descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) + if (layouts.size() == descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) { // create compute resources computeResource = graphStorage->resourceHub->Create(); - auto computeResourceLayout = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; + auto computeResourceLayout = layouts[descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 }); #ifdef _DEBUG for (auto set : computeResource->descSet->GetVkHandle()) @@ -94,21 +94,21 @@ namespace SHADE // bind the compute pipeline cmdBuffer->BindPipeline(computePipeline); - auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE); // bind render graph resource - cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {}); + cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {}); // bind compute resource if (computeResource) { - cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]); + cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]); } // bind camera data if (renderer) - renderer->BindDescriptorSet (cmdBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + renderer->BindDescriptorSet (cmdBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); // dispatch compute cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1); @@ -120,11 +120,14 @@ namespace SHADE void SHRenderGraphNodeCompute::HandleResize(void) noexcept { - auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings; - uint32_t renderGraphResourceSetIndex = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE); + // We need to get from mappings because we want the introspected layout from the vector of layouts (of which the first few are predefined) + uint32_t RENDER_GRAPH_RESOURCE_SET_INDEX = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).at (SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE); + + // Since the descriptor set is standalone, the index we want to use is not the one in the shaders, it should always be 0. + uint32_t RENDER_GRAPH_RESOURCE_UPDATE_SET_INDEX = 0; // Get the layout for the render graph resource. We can index it this way because the container returned is a container of layouts that includes the global ones - auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[renderGraphResourceSetIndex]; + auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[RENDER_GRAPH_RESOURCE_SET_INDEX]; // everything below here needs resizing for (uint32_t frameIndex = 0; frameIndex < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++frameIndex) @@ -137,8 +140,8 @@ namespace SHADE uint32_t imageIndex = (resources[i]->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0; SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle{}, vk::ImageLayout::eGeneral); - graphResourceDescSets[frameIndex]->ModifyWriteDescImage(renderGraphResourceSetIndex, binding.BindPoint, { &vsl, 1 }); - graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(renderGraphResourceSetIndex, binding.BindPoint); + graphResourceDescSets[frameIndex]->ModifyWriteDescImage(RENDER_GRAPH_RESOURCE_UPDATE_SET_INDEX, binding.BindPoint, { &vsl, 1 }); + graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(RENDER_GRAPH_RESOURCE_UPDATE_SET_INDEX, binding.BindPoint); ++i; } } @@ -200,16 +203,19 @@ namespace SHADE renderer = inRenderer; } - void SHRenderGraphNodeCompute::ModifyWriteDescBufferComputeResource(uint32_t set, uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept + void SHRenderGraphNodeCompute::ModifyWriteDescBufferComputeResource(uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept { - computeResource->descSet->ModifyWriteDescBuffer(set, binding, buffers, offset, range); - computeResource->descSet->UpdateDescriptorSetBuffer(set, binding); + static constexpr uint32_t COMPUTE_RESOURCE_SET_INDEX = 0; + + computeResource->descSet->ModifyWriteDescBuffer(COMPUTE_RESOURCE_SET_INDEX, binding, buffers, offset, range); + computeResource->descSet->UpdateDescriptorSetBuffer(COMPUTE_RESOURCE_SET_INDEX, binding); } - void SHRenderGraphNodeCompute::ModifyWriteDescImageComputeResource(uint32_t set, uint32_t binding, std::span const& viewSamplerLayouts) noexcept + void SHRenderGraphNodeCompute::ModifyWriteDescImageComputeResource(uint32_t binding, std::span const& viewSamplerLayouts) noexcept { - computeResource->descSet->ModifyWriteDescImage(set, binding, viewSamplerLayouts); - computeResource->descSet->UpdateDescriptorSetImages(set, binding); + static constexpr uint32_t COMPUTE_RESOURCE_SET_INDEX = 0; + computeResource->descSet->ModifyWriteDescImage(COMPUTE_RESOURCE_SET_INDEX, binding, viewSamplerLayouts); + computeResource->descSet->UpdateDescriptorSetImages(COMPUTE_RESOURCE_SET_INDEX, binding); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index cba37f80..dc3ca886 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -82,8 +82,8 @@ namespace SHADE void SetDynamicOffsets (std::span perFrameSizes) noexcept; void SetRenderer (Handle inRenderer) noexcept; - void ModifyWriteDescBufferComputeResource (uint32_t set, uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; - void ModifyWriteDescImageComputeResource(uint32_t set, uint32_t binding, std::span const& viewSamplerLayouts) noexcept; + void ModifyWriteDescBufferComputeResource (uint32_t binding, std::span> const& buffers, uint32_t offset, uint32_t range) noexcept; + void ModifyWriteDescImageComputeResource(uint32_t binding, std::span const& viewSamplerLayouts) noexcept; friend class SHRenderGraph; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h index d473dd2a..b0cd40bc 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphStorage.h @@ -7,7 +7,7 @@ namespace SHADE { class SHVkLogicalDevice; class SHVkSwapchain; - class SHPredefinedData; + class SHGraphicsPredefinedData; class SHVkDescriptorPool; class SHRenderGraphResource; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp index 4c575c99..80260b7b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp @@ -1,7 +1,7 @@ #include "SHpch.h" #include "SHRenderToSwapchainImageSystem.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" #include "Graphics/RenderGraph/SHRenderGraphNode.h" #include "Graphics/RenderGraph/SHSubpass.h" #include "Graphics/SHVkUtil.h" @@ -24,7 +24,7 @@ namespace SHADE auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams { .shaderModules = {shaderModules.first, shaderModules.second}, - .predefinedDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts + .predefinedDescSetLayouts = {} }); pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index e5052f59..c903553b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -13,7 +13,7 @@ #include "SHRenderGraphResource.h" #include "Graphics/MiddleEnd/Interface/SHViewport.h" #include "Graphics/MiddleEnd/Interface/SHRenderer.h" -#include "Graphics/MiddleEnd/GlobalData/SHPredefinedData.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" namespace SHADE { @@ -224,10 +224,10 @@ namespace SHADE commandBuffer->SetViewportScissor(static_cast(w), static_cast(h), w, h); } - auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); if (renderer) - renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); // Draw all the batches superBatch->Draw(commandBuffer, frameIndex); @@ -245,11 +245,11 @@ namespace SHADE UpdateWriteDescriptors(); } - void SHSubpass::BindDescriptorInputDescriptorSets(Handle cmdBuffer, uint32_t frameIndex) const noexcept + void SHSubpass::BindInputDescriptorSets(Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) const noexcept { if (!inputImageDescriptorSets.empty()) { - cmdBuffer->BindDescriptorSet(inputImageDescriptorSets[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, { }); + cmdBuffer->BindDescriptorSet(inputImageDescriptorSets[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, setIndex, { }); } } @@ -356,8 +356,13 @@ namespace SHADE // Update descriptor sets auto args = std::make_tuple(resource->GetImageView(viewIndex), inputSamplers[i], descriptorLayout); - group->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint, std::span{&args, 1}); - group->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint); + + + // Since the descriptor set is standalone, the index we want to use is not the one in the shaders, it should always be 0. + uint32_t RENDER_GRAPH_RESOURCE_SET_INDEX = 0; + + group->ModifyWriteDescImage(RENDER_GRAPH_RESOURCE_SET_INDEX, binding.BindPoint, std::span{&args, 1}); + group->UpdateDescriptorSetImages(RENDER_GRAPH_RESOURCE_SET_INDEX, binding.BindPoint); } ++i; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index b5c5c8b1..66d41ffd 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -121,7 +121,7 @@ namespace SHADE // Runtime functions void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; - void BindDescriptorInputDescriptorSets (Handle cmdBuffer, uint32_t frameIndex) const noexcept; + void BindInputDescriptorSets (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) const noexcept; void Init(SHResourceHub& resourceManager) noexcept; diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index b560acae..ee02478a 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -10,6 +10,7 @@ #include "ECS_Base/Managers/SHComponentManager.h" #include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" #include "Tools/Logger/SHLog.h" +#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h" namespace SHADE @@ -264,7 +265,8 @@ namespace SHADE if(spec.properties.IsDefined()) { auto fragShader = SHResourceManager::LoadOrGet(spec.fragShader); - auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); + auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); + auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); int const varCount = static_cast(interface->GetVariableCount()); for (int i = 0; i < varCount; ++i) diff --git a/SHADE_Engine/src/Tools/SHEnumWrapper.h b/SHADE_Engine/src/Tools/SHEnumWrapper.h new file mode 100644 index 00000000..7c37659e --- /dev/null +++ b/SHADE_Engine/src/Tools/SHEnumWrapper.h @@ -0,0 +1,67 @@ +#pragma once + +#include + +namespace SHADE +{ + template + class SHEnumWrapper + { + public: + using UnderlyingType = typename std::underlying_type_t; + + private: + UnderlyingType mask; + + public: + + constexpr SHEnumWrapper(void) noexcept + : mask{ 0 } + { + + }; + + constexpr SHEnumWrapper(BitType bit) noexcept + : mask{ static_cast(bit) } + { + + }; + + constexpr SHEnumWrapper(SHEnumWrapper const& rhs) noexcept = default; + constexpr SHEnumWrapper& operator= (SHEnumWrapper const& rhs) noexcept = default; + + constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept + : mask{ flags } + { + + }; + + constexpr SHEnumWrapper operator| (SHEnumWrapper const& rhs) const noexcept + { + return static_cast> (mask | rhs.mask); + }; + + constexpr SHEnumWrapper operator& (SHEnumWrapper const& rhs) const noexcept + { + return static_cast> (mask & rhs.mask); + }; + + constexpr operator UnderlyingType() const noexcept + { + return mask; + }; + }; + + template>> + inline BitType operator|(const BitType& left, const BitType& right) + { + return static_cast(static_cast(left) | static_cast(right)); + } + + template>> + inline BitType operator&(const BitType& left, const BitType& right) + { + return static_cast(static_cast(left) & static_cast(right)); + } + +} diff --git a/SHADE_Engine/src/Tools/Utilities/SHUtilities.h b/SHADE_Engine/src/Tools/Utilities/SHUtilities.h index c3492f13..6cdd91ee 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHUtilities.h +++ b/SHADE_Engine/src/Tools/Utilities/SHUtilities.h @@ -43,73 +43,6 @@ namespace SHADE static constexpr OutputType ConvertEnum(InputType enumClassMember) noexcept; }; - template - class SHEnumWrapper - { - public: - using UnderlyingType = typename std::underlying_type_t; - - private: - UnderlyingType mask; - - public: - - constexpr SHEnumWrapper(void) noexcept - : mask{ 0 } - { - - }; - - constexpr SHEnumWrapper(BitType bit) noexcept - : mask{ static_cast(bit) } - { - - }; - - constexpr SHEnumWrapper(SHEnumWrapper const& rhs) noexcept = default; - constexpr SHEnumWrapper& operator= (SHEnumWrapper const& rhs) noexcept = default; - - constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept - : mask{ flags } - { - - }; - - constexpr SHEnumWrapper operator| (SHEnumWrapper const& rhs) const noexcept - { - return static_cast> (mask | rhs.mask); - }; - - constexpr SHEnumWrapper operator& (SHEnumWrapper const& rhs) const noexcept - { - return static_cast> (mask & rhs.mask); - }; - - constexpr operator UnderlyingType() const noexcept - { - return mask; - }; - }; - - template>> - inline BitType operator|(const BitType& left, const BitType& right) - { - return static_cast(static_cast(left) | static_cast(right)); - } - - template>> - inline BitType operator&(const BitType& left, const BitType& right) - { - return static_cast(static_cast(left) & static_cast(right)); - } - - template - std::ostream& operator<<(std::ostream& os, EnumType const& type) - { - os << static_cast(type); - return os; - } - } // namespace SHADE #include "SHUtilities.hpp" From 8e2c32d11036ada6dd2f15c165f7d8d2c0c06808 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Thu, 29 Dec 2022 14:29:25 +0800 Subject: [PATCH 14/24] Graphics refactor more or less tested and working - Descriptors sets are now independent from a set index. Camera matrices for example can be bound to set index 1 for the batching system but index 2 for compute shaders. - Truly global descriptors sets (misc data, textures and light data) are now manually bound to a global static class that allows retrieval of these sets to be bound whenever in the middle end. - Predefined descriptor set layouts (but not truly global such as camera data, materials and font) have their layouts predefined in a class and used for descriptor set initialization within the middle end. The sets themselves are allocated using these layouts (also accessible globally). - Descriptor sets that are more flexible with their bindings such as render graph resources are introspected from shaders and not predefined at all (though their types are recorded in SHGraphicsPredefinedData to avoid magic numbers when binding descriptor sets in some systems). - Systems now have fixed mappings for descriptors used in shaders and these are defined in SHGraphicsPredefinedData. Batching for example has 3 fixed descriptors: Static global bound at 0, camera data bound at 1, materials bound at 2. - Viewports no longer contain renderers and renderers no longer contain render graphs. The graphics system only has 1 render graph and subpasses can have both viewports and renderers bound to them to have options for viewport/scissor and camera settings. - Light data is now bound before every compute system. - There is only 1 render graph in the entire system and contains only 6 nodes: G-Buffer pass (with lighting compute pass), debug draw with depth, debug draw, screen space pass, dummy pass for transition to input attachment for imGui and lastly the imGui pass for rendering editor to swapchain. --- Assets/Scenes/MainGame.shade | 293 ++++++++++++++++++ SHADE_Engine/src/Camera/SHCameraComponent.cpp | 2 +- .../MaterialInspector/SHMaterialInspector.cpp | 2 +- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 6 +- .../GlobalData/SHDescriptorMappings.cpp | 2 +- .../GlobalData/SHDescriptorMappings.h | 6 +- .../GlobalData/SHGlobalDescriptorSets.cpp | 2 +- .../GlobalData/SHGraphicsPredefinedData.cpp | 44 +-- .../GlobalData/SHGraphicsPredefinedData.h | 14 +- .../GlobalData/SHPredefinedDescriptorTypes.h | 19 ++ .../MiddleEnd/Interface/SHGraphicsConstants.h | 27 -- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 213 +------------ .../MiddleEnd/Interface/SHGraphicsSystem.h | 1 - .../MiddleEnd/Interface/SHMaterial.cpp | 2 +- .../Interface/SHMaterialInstance.cpp | 2 +- .../MiddleEnd/Interface/SHRenderer.cpp | 2 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 2 +- .../SHTextRenderingSubSystem.cpp | 6 +- .../MiddleEnd/Textures/SHTextureLibrary.cpp | 2 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 2 +- .../RenderGraph/SHRenderGraphNode.cpp | 4 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 14 +- .../RenderGraph/SHRenderGraphResource.cpp | 9 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 2 +- .../src/Graphics/Swapchain/SHVkSwapchain.cpp | 10 + .../src/Graphics/Swapchain/SHVkSwapchain.h | 2 + .../Serialization/SHSerializationHelper.hpp | 2 +- 27 files changed, 405 insertions(+), 287 deletions(-) create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 29cfdda0..49602e78 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -474,6 +474,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 10, y: 0.0500000007, z: 18} Friction: 0.400000006 @@ -511,6 +512,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.200000003, z: 0.25} Friction: 0.400000006 @@ -519,6 +521,7 @@ Position Offset: {x: 0, y: 2.0999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.899999976, z: 0.25} Friction: 0.400000006 @@ -527,6 +530,7 @@ Position Offset: {x: 0, y: 0.449999988, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -535,6 +539,7 @@ Position Offset: {x: -0.449999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -561,6 +566,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.10000002, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -569,6 +575,7 @@ Position Offset: {x: 0.449999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.25, y: 2.20000005, z: 1.10000002} Friction: 0.400000006 @@ -595,6 +602,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -621,6 +629,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -647,6 +656,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -673,6 +683,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -699,6 +710,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -725,6 +737,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.10000002, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -733,6 +746,7 @@ Position Offset: {x: 0.449999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.25, y: 2.20000005, z: 1.10000002} Friction: 0.400000006 @@ -759,6 +773,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -785,6 +800,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -811,6 +827,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -837,6 +854,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.150000006, z: 0.25} Friction: 0.400000006 @@ -845,6 +863,7 @@ Position Offset: {x: 0, y: 2.125, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -853,6 +872,7 @@ Position Offset: {x: -0.455000013, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -897,6 +917,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.800000012, y: 2, z: 0.0350000001} Friction: 0.400000006 @@ -923,6 +944,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -949,6 +971,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.10000002, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -957,6 +980,7 @@ Position Offset: {x: 0.449999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.25, y: 2.20000005, z: 1.10000002} Friction: 0.400000006 @@ -983,6 +1007,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1009,6 +1034,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1035,6 +1061,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1061,6 +1088,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1087,6 +1115,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1113,6 +1142,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.150000006, z: 0.25} Friction: 0.400000006 @@ -1121,6 +1151,7 @@ Position Offset: {x: 0, y: 2.125, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1129,6 +1160,7 @@ Position Offset: {x: -0.455000013, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1173,6 +1205,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.800000012, y: 2, z: 0.0350000001} Friction: 0.400000006 @@ -1199,6 +1232,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1225,6 +1259,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1251,6 +1286,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1277,6 +1313,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1303,6 +1340,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -1351,6 +1389,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1377,6 +1416,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1403,6 +1443,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1429,6 +1470,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1455,6 +1497,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1492,6 +1535,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1518,6 +1562,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1544,6 +1589,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1570,6 +1616,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1596,6 +1643,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1633,6 +1681,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1659,6 +1708,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1685,6 +1735,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1711,6 +1762,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1737,6 +1789,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1774,6 +1827,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1800,6 +1854,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1826,6 +1881,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1852,6 +1908,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1878,6 +1935,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1915,6 +1973,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1941,6 +2000,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1967,6 +2027,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -1993,6 +2054,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -2019,6 +2081,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -2171,6 +2234,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -2197,6 +2261,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -2234,6 +2299,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -2260,6 +2326,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.0500000007, z: 2} Friction: 0.400000006 @@ -2297,6 +2364,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.10000002, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2305,6 +2373,7 @@ Position Offset: {x: 0.449999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.25, y: 2.20000005, z: 1.10000002} Friction: 0.400000006 @@ -2331,6 +2400,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.10000002, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2339,6 +2409,7 @@ Position Offset: {x: 0.449999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.25, y: 2.20000005, z: 1.10000002} Friction: 0.400000006 @@ -2365,6 +2436,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.200000003, z: 0.25} Friction: 0.400000006 @@ -2373,6 +2445,7 @@ Position Offset: {x: 0, y: 2.0999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 0.899999976, z: 0.25} Friction: 0.400000006 @@ -2381,6 +2454,7 @@ Position Offset: {x: 0, y: 0.449999988, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2389,6 +2463,7 @@ Position Offset: {x: -0.949999988, y: 1.10000002, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2415,6 +2490,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2441,6 +2517,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 2, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2467,6 +2544,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2493,6 +2571,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 2.20000005, z: 0.25} Friction: 0.400000006 @@ -2519,6 +2598,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -2527,6 +2607,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -2575,6 +2656,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -2601,6 +2683,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -2627,6 +2710,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -2653,6 +2737,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -2661,6 +2746,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -2669,6 +2755,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -2677,6 +2764,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -2685,6 +2773,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -2711,6 +2800,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -2719,6 +2809,7 @@ Position Offset: {x: -0.310000002, y: -0.219999999, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -2727,6 +2818,7 @@ Position Offset: {x: 0.147, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -2735,6 +2827,7 @@ Position Offset: {x: -0.757000029, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -2743,6 +2836,7 @@ Position Offset: {x: -0.310000002, y: -0.0700000003, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -2769,6 +2863,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -2777,6 +2872,7 @@ Position Offset: {x: -0.310000002, y: -0.219999999, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -2785,6 +2881,7 @@ Position Offset: {x: 0.147, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -2793,6 +2890,7 @@ Position Offset: {x: -0.757000029, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -2801,6 +2899,7 @@ Position Offset: {x: -0.310000002, y: -0.0700000003, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -2827,6 +2926,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -2835,6 +2935,7 @@ Position Offset: {x: -0.310000002, y: -0.219999999, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -2843,6 +2944,7 @@ Position Offset: {x: 0.147, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -2851,6 +2953,7 @@ Position Offset: {x: -0.757000029, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -2859,6 +2962,7 @@ Position Offset: {x: -0.310000002, y: -0.0700000003, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -2885,6 +2989,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -2911,6 +3016,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.725000024, z: 0.850000024} Friction: 0.400000006 @@ -2952,6 +3058,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.800000012, y: 0.0500000007, z: 0.800000012} Friction: 0.400000006 @@ -2978,6 +3085,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -2986,6 +3094,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -2994,6 +3103,7 @@ Position Offset: {x: 0, y: 0.860000014, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3002,6 +3112,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3010,6 +3121,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3018,6 +3130,7 @@ Position Offset: {x: -0.444999993, y: 0.600000024, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.300000012, z: 1} Friction: 0.400000006 @@ -3026,6 +3139,7 @@ Position Offset: {x: 0.444999993, y: 1.04999995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3034,6 +3148,7 @@ Position Offset: {x: 0, y: 1.04999995, z: 0.444999993} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3042,6 +3157,7 @@ Position Offset: {x: 0, y: 1.04999995, z: -0.444999993} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3068,6 +3184,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.07500005, z: 0.925000012} Friction: 0.400000006 @@ -3094,6 +3211,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3102,6 +3220,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3110,6 +3229,7 @@ Position Offset: {x: 0, y: 0.860000014, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3118,6 +3238,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3126,6 +3247,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3134,6 +3256,7 @@ Position Offset: {x: -0.444999993, y: 0.600000024, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.300000012, z: 1} Friction: 0.400000006 @@ -3142,6 +3265,7 @@ Position Offset: {x: 0.444999993, y: 1.04999995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3150,6 +3274,7 @@ Position Offset: {x: 0, y: 1.04999995, z: 0.444999993} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3158,6 +3283,7 @@ Position Offset: {x: 0, y: 1.04999995, z: -0.444999993} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3184,6 +3310,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.07500005, z: 0.925000012} Friction: 0.400000006 @@ -3210,6 +3337,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3236,6 +3364,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 1.29999995, z: 1} Friction: 0.400000006 @@ -3244,6 +3373,7 @@ Position Offset: {x: 0, y: 0.699999988, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.600000024, y: 1.70000005, z: 0.0700000003} Friction: 0.400000006 @@ -3252,6 +3382,7 @@ Position Offset: {x: 0, y: 0.850000024, z: -0.5} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.600000024, y: 1.70000005, z: 0.0700000003} Friction: 0.400000006 @@ -3278,6 +3409,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.300000012, y: 0.800000012, z: 0.300000012} Friction: 0.400000006 @@ -3315,6 +3447,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.699999988, y: 0.0500000007, z: 1.20000005} Friction: 0.400000006 @@ -3323,6 +3456,7 @@ Position Offset: {x: 0, y: 0.77700001, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -3331,6 +3465,7 @@ Position Offset: {x: -0.449999988, y: 0.400000006, z: -0.850000024} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -3339,6 +3474,7 @@ Position Offset: {x: -0.449999988, y: 0.400000006, z: 0.850000024} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -3347,6 +3483,7 @@ Position Offset: {x: 0.449999988, y: 0.400000006, z: 0.850000024} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -3373,6 +3510,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -3381,6 +3519,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -3407,6 +3546,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -3415,6 +3555,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -3441,6 +3582,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -3449,6 +3591,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -3475,6 +3618,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -3483,6 +3627,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -3520,6 +3665,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3528,6 +3674,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3536,6 +3683,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3544,6 +3692,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3552,6 +3701,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3578,6 +3728,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3586,6 +3737,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3594,6 +3746,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3602,6 +3755,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3610,6 +3764,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3636,6 +3791,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3644,6 +3800,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3652,6 +3809,7 @@ Position Offset: {x: 0, y: 0.860000014, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3660,6 +3818,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3668,6 +3827,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3676,6 +3836,7 @@ Position Offset: {x: -0.444999993, y: 0.600000024, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.300000012, z: 1} Friction: 0.400000006 @@ -3684,6 +3845,7 @@ Position Offset: {x: 0.444999993, y: 1.04999995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3692,6 +3854,7 @@ Position Offset: {x: 0, y: 1.04999995, z: 0.444999993} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3700,6 +3863,7 @@ Position Offset: {x: 0, y: 1.04999995, z: -0.444999993} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.300000012, z: 0.100000001} Friction: 0.400000006 @@ -3726,6 +3890,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.07500005, z: 0.462500006} Friction: 0.400000006 @@ -3752,6 +3917,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.07500005, z: 0.462500006} Friction: 0.400000006 @@ -3778,6 +3944,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3786,6 +3953,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3794,6 +3962,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3802,6 +3971,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3810,6 +3980,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -3836,6 +4007,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -3844,6 +4016,7 @@ Position Offset: {x: -0.310000002, y: -0.519999981, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.699999988, z: 0.870000005} Friction: 0.400000006 @@ -3852,6 +4025,7 @@ Position Offset: {x: 0.147, y: -0.170000002, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.699999988, z: 0.870000005} Friction: 0.400000006 @@ -3860,6 +4034,7 @@ Position Offset: {x: -0.757000029, y: -0.170000002, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.699999988, z: 0.0450000018} Friction: 0.400000006 @@ -3868,6 +4043,7 @@ Position Offset: {x: -0.310000002, y: -0.170000002, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.699999988, z: 0.0450000018} Friction: 0.400000006 @@ -3894,6 +4070,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -3902,6 +4079,7 @@ Position Offset: {x: -0.310000002, y: -0.219999999, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -3910,6 +4088,7 @@ Position Offset: {x: 0.147, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -3918,6 +4097,7 @@ Position Offset: {x: -0.757000029, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -3926,6 +4106,7 @@ Position Offset: {x: -0.310000002, y: -0.0700000003, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -3952,6 +4133,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3960,6 +4142,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -3968,6 +4151,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3976,6 +4160,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -3984,6 +4169,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4010,6 +4196,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4036,6 +4223,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4062,6 +4250,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4088,6 +4277,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4114,6 +4304,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4140,6 +4331,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.725000024, z: 0.850000024} Friction: 0.400000006 @@ -4181,6 +4373,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.800000012, y: 0.0500000007, z: 0.800000012} Friction: 0.400000006 @@ -4207,6 +4400,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4233,6 +4427,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.725000024, z: 0.850000024} Friction: 0.400000006 @@ -4274,6 +4469,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.800000012, y: 0.0500000007, z: 0.800000012} Friction: 0.400000006 @@ -4300,6 +4496,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4308,6 +4505,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4316,6 +4514,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4324,6 +4523,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4332,6 +4532,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4358,6 +4559,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4366,6 +4568,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4374,6 +4577,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4382,6 +4586,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4390,6 +4595,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4416,6 +4622,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4424,6 +4631,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4432,6 +4640,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4440,6 +4649,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4448,6 +4658,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4474,6 +4685,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4482,6 +4694,7 @@ Position Offset: {x: 0, y: 0.0250000004, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.0500000007, z: 1} Friction: 0.400000006 @@ -4490,6 +4703,7 @@ Position Offset: {x: 0, y: 1.17499995, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4498,6 +4712,7 @@ Position Offset: {x: 0, y: 0.600000024, z: 0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.20000005, z: 0.0500000007} Friction: 0.400000006 @@ -4506,6 +4721,7 @@ Position Offset: {x: 0, y: 0.600000024, z: -0.474999994} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 1.20000005, z: 1} Friction: 0.400000006 @@ -4532,6 +4748,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -4540,6 +4757,7 @@ Position Offset: {x: -0.310000002, y: -0.519999981, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.699999988, z: 0.870000005} Friction: 0.400000006 @@ -4548,6 +4766,7 @@ Position Offset: {x: 0.147, y: -0.170000002, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.699999988, z: 0.870000005} Friction: 0.400000006 @@ -4556,6 +4775,7 @@ Position Offset: {x: -0.757000029, y: -0.170000002, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.699999988, z: 0.0450000018} Friction: 0.400000006 @@ -4564,6 +4784,7 @@ Position Offset: {x: -0.310000002, y: -0.170000002, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.699999988, z: 0.0450000018} Friction: 0.400000006 @@ -4590,6 +4811,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.970000029, y: 0.0250000004, z: 0.870000005} Friction: 0.400000006 @@ -4598,6 +4820,7 @@ Position Offset: {x: -0.310000002, y: -0.219999999, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -4606,6 +4829,7 @@ Position Offset: {x: 0.147, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0450000018, y: 0.349999994, z: 0.870000005} Friction: 0.400000006 @@ -4614,6 +4838,7 @@ Position Offset: {x: -0.757000029, y: -0.0700000003, z: 0.00499999989} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -4622,6 +4847,7 @@ Position Offset: {x: -0.310000002, y: -0.0700000003, z: -0.425000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.959999979, y: 0.349999994, z: 0.0450000018} Friction: 0.400000006 @@ -4648,6 +4874,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.300000012, y: 0.800000012, z: 0.300000012} Friction: 0.400000006 @@ -4685,6 +4912,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -4711,6 +4939,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -4737,6 +4966,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -4763,6 +4993,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.899999976, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -4789,6 +5020,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -4797,6 +5029,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -4823,6 +5056,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -4831,6 +5065,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -4857,6 +5092,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -4865,6 +5101,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -4902,6 +5139,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -4928,6 +5166,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -4954,6 +5193,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -4980,6 +5220,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.899999976, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -5006,6 +5247,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5014,6 +5256,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5040,6 +5283,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5048,6 +5292,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5085,6 +5330,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -5111,6 +5357,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -5137,6 +5384,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -5163,6 +5411,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.899999976, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -5189,6 +5438,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5197,6 +5447,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5223,6 +5474,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5231,6 +5483,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5257,6 +5510,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.699999988, y: 0.0500000007, z: 1.20000005} Friction: 0.400000006 @@ -5265,6 +5519,7 @@ Position Offset: {x: 0, y: 0.77700001, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -5273,6 +5528,7 @@ Position Offset: {x: -0.25, y: 0.400000006, z: -0.550000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -5281,6 +5537,7 @@ Position Offset: {x: -0.25, y: 0.400000006, z: 0.550000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -5289,6 +5546,7 @@ Position Offset: {x: 0.25, y: 0.400000006, z: 0.550000012} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0500000007, y: 0.800000012, z: 0.0500000007} Friction: 0.400000006 @@ -5315,6 +5573,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.439999998, z: 0.400000006} Friction: 0.400000006 @@ -5323,6 +5582,7 @@ Position Offset: {x: 0, y: 0.219999999, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.0399999991, y: 1, z: 0.400000006} Friction: 0.400000006 @@ -5360,6 +5620,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -5386,6 +5647,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1.20000005, y: 0.100000001, z: 2.20000005} Friction: 0.400000006 @@ -5412,6 +5674,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 0.100000001, z: 1.89999998} Friction: 0.400000006 @@ -5438,6 +5701,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -5446,6 +5710,7 @@ Position Offset: {x: 0, y: 0.5, z: -0.954999983} Rotation Offset: {x: 0, y: 0, z: 0} - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.100000001} Friction: 0.400000006 @@ -8235,6 +8500,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012} Friction: 0.400000006 @@ -8279,6 +8545,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012} Friction: 0.400000006 @@ -8323,6 +8590,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012} Friction: 0.400000006 @@ -8367,6 +8635,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.5, y: 0.150000006, z: 0.5} Friction: 0.400000006 @@ -8411,6 +8680,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.5, y: 0.150000006, z: 0.5} Friction: 0.400000006 @@ -8455,6 +8725,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.5, y: 0.150000006, z: 0.5} Friction: 0.400000006 @@ -8499,6 +8770,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.200000003, y: 0.200000003, z: 0.200000003} Friction: 0.400000006 @@ -8543,6 +8815,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.200000003, y: 0.200000003, z: 0.200000003} Friction: 0.400000006 @@ -8587,6 +8860,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.200000003, y: 0.200000003, z: 0.200000003} Friction: 0.400000006 @@ -8633,6 +8907,7 @@ Collider Component: Colliders: - Is Trigger: true + Collision Tag: 1 Type: Box Half Extents: {x: 1.79999995, y: 1, z: 1} Friction: 0.400000006 @@ -8671,6 +8946,7 @@ Collider Component: Colliders: - Is Trigger: true + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1, z: 0.200000003} Friction: 0.400000006 @@ -8773,6 +9049,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.400000006, y: 0.5, z: 0.300000012} Friction: 0.400000006 @@ -8916,6 +9193,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.200000003, y: 0.100000001, z: 0.200000003} Friction: 0.400000006 @@ -8960,6 +9238,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9000,6 +9279,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.200000003} Friction: 0.400000006 @@ -9040,6 +9320,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9080,6 +9361,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9120,6 +9402,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.200000003, y: 0.100000001, z: 0.200000003} Friction: 0.400000006 @@ -9164,6 +9447,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9204,6 +9488,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.200000003} Friction: 0.400000006 @@ -9244,6 +9529,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9284,6 +9570,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9324,6 +9611,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.200000003, y: 0.100000001, z: 0.200000003} Friction: 0.400000006 @@ -9368,6 +9656,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9408,6 +9697,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.200000003} Friction: 0.400000006 @@ -9448,6 +9738,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9488,6 +9779,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006} Friction: 0.400000006 @@ -9611,6 +9903,7 @@ Collider Component: Colliders: - Is Trigger: false + Collision Tag: 1 Type: Box Half Extents: {x: 1, y: 1.79999995, z: 0.400000006} Friction: 0.400000006 diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.cpp b/SHADE_Engine/src/Camera/SHCameraComponent.cpp index 7fc71db1..8b2f50d9 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraComponent.cpp @@ -226,7 +226,7 @@ namespace SHADE const SHMatrix& SHCameraComponent::GetPerspectiveMatrix() const noexcept { - return orthoProjMatrix; + return perspProjMatrix; } //void SHCameraComponent::SetMainCamera(size_t directorCameraIndex) noexcept diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp index ddcef902..537cfc55 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -201,7 +201,7 @@ namespace SHADE // Get interface for the shader combination auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface ( - mappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + mappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA ); if (!interface) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index ab36a7b4..77f7706e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -416,7 +416,7 @@ namespace SHADE // - Material Properties Data const Handle SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - descMappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + descMappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, vk::ShaderStageFlagBits::eFragment ); @@ -578,7 +578,7 @@ namespace SHADE matPropsDescSet[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, - descMappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + descMappings.at(SHPredefinedDescriptorTypes::MATERIALS), dynamicOffset ); } @@ -611,7 +611,7 @@ namespace SHADE { matPropsDescSet[frameIndex] = descPool->Allocate ( - SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS), + SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS), { 0 } ); #ifdef _DEBUG diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp index c2b7c042..075f0e06 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp @@ -3,7 +3,7 @@ namespace SHADE { - void SHDescriptorMappings::AddMappings(std::initializer_list> inMappings) noexcept + void SHDescriptorMappings::AddMappings(std::initializer_list> inMappings) noexcept { for (auto& map : inMappings) mappings.emplace(map); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h index 67480e7e..3e94a87a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h @@ -1,14 +1,14 @@ #pragma once #include -#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h" namespace SHADE { class SHDescriptorMappings { public: - using MapType = std::unordered_map; + using MapType = std::unordered_map; private: //! To map an enum value from descriptor set types to set indices @@ -18,7 +18,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void AddMappings (std::initializer_list> inMappings) noexcept; + void AddMappings (std::initializer_list> inMappings) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp index 9e1263cf..fd94968e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp @@ -12,7 +12,7 @@ namespace SHADE //void SHGlobalDescriptorSets::BindLightingData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t firstSet) noexcept //{ // // Bind descriptor set for light data - // cmdBuffer->BindDescriptorSet(SHGlobalDescriptorSets::GetLightDescriptorSet(), SH_PIPELINE_TYPE::COMPUTE, descMappings[SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS], const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); + // cmdBuffer->BindDescriptorSet(SHGlobalDescriptorSets::GetLightDescriptorSet(), SH_PIPELINE_TYPE::COMPUTE, descMappings[SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::LIGHTS], const std::span{ TEX_DYNAMIC_OFFSET.data(), 1 }); //} void SHGlobalDescriptorSets::BindLightingData(Handle cmdBuffer, SH_PIPELINE_TYPE pipelineType, uint32_t setIndex, uint32_t frameIndex) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index 36566108..a533249b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -24,25 +24,25 @@ namespace SHADE perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descMappings.AddMappings ({ - {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, - {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1}, - {SHGraphicsConstants::DescriptorSetTypes::MATERIALS, 2}, + {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, + {SHPredefinedDescriptorTypes::CAMERA, 1}, + {SHPredefinedDescriptorTypes::MATERIALS, 2}, }); perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings ({ - {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, - {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1}, - {SHGraphicsConstants::DescriptorSetTypes::FONT, 2}, + {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, + {SHPredefinedDescriptorTypes::CAMERA, 1}, + {SHPredefinedDescriptorTypes::FONT, 2}, }); perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descMappings.AddMappings ({ - {SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0}, - {SHGraphicsConstants::DescriptorSetTypes::LIGHTS, 1}, - {SHGraphicsConstants::DescriptorSetTypes::CAMERA, 2}, - {SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE, 3}, - {SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE, 4}, + {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, + {SHPredefinedDescriptorTypes::LIGHTS, 1}, + {SHPredefinedDescriptorTypes::CAMERA, 2}, + {SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE, 3}, + {SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE, 4}, }); } @@ -159,23 +159,23 @@ namespace SHADE perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts ( - SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA | + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS ); perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts ( - SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA | + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::FONT ); perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descSetLayouts = GetPredefinedDescSetLayouts ( - SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA | - SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA | + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA | + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::LIGHTS ); } @@ -198,10 +198,10 @@ namespace SHADE InitDummyPipelineLayouts (logicalDevice); } - std::vector> SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept + std::vector> SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept { std::vector> layoutsFound; - for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i) + for (uint8_t i = 0; i < numPredefinedDescSetLayoutTypes; ++i) { if (types & (static_cast(1) << i)) layoutsFound.push_back(predefinedLayouts[i]); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index ac10093a..f46cb883 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -18,6 +18,18 @@ namespace SHADE class SH_API SHGraphicsPredefinedData { public: + static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64; + + // This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData + enum class PredefinedDescSetLayoutTypes : uint64_t + { + STATIC_DATA = 0x01, + LIGHTS = 0x02, + CAMERA = 0x04, + MATERIALS = 0x08, + FONT = 0x10, + }; + enum class SystemType { BATCHING = 0, @@ -76,7 +88,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; + static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; static SHVertexInputState const& GetDefaultViState (void) noexcept; static PerSystem const& GetSystemData (SystemType systemType) noexcept; static SHDescriptorMappings::MapType const& GetMappings (SystemType systemType) noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h new file mode 100644 index 00000000..931101f4 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h @@ -0,0 +1,19 @@ +#pragma once + +namespace SHADE +{ + // This enum is different from PredefinedDescSetLayoutTypes in that it is used to initialize a hash table to + // with the values here as keys and set indices as values. It is worth noting that some values here + // are not in the above table. This is because those values don't have predefined descriptor set layouts. + // Their layouts and set indices are instead created through introspection in the pipeline layout. + enum class SHPredefinedDescriptorTypes + { + STATIC_DATA, + LIGHTS, + CAMERA, + MATERIALS, + FONT, + RENDER_GRAPH_RESOURCE, + RENDER_GRAPH_NODE_COMPUTE_RESOURCE, + }; +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 86742b53..c889a321 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -25,33 +25,6 @@ namespace SHADE struct SHGraphicsConstants { public: - static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64; - - // This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData - enum class PredefinedDescSetLayoutTypes : uint64_t - { - STATIC_DATA = 0x01, - LIGHTS = 0x02, - CAMERA = 0x04, - MATERIALS = 0x08, - FONT = 0x10, - }; - - // This enum is different from the one above in that it is used to initialize a hash table to - // with the values here as keys and set indices as values. It is worth noting that some values here - // are not in the above table. This is because those values don't have predefined descriptor set layouts. - // Their layouts and set indices are instead created through introspection in the pipeline layout. - enum class DescriptorSetTypes - { - STATIC_DATA, - LIGHTS, - CAMERA, - MATERIALS, - FONT, - RENDER_GRAPH_RESOURCE, - RENDER_GRAPH_NODE_COMPUTE_RESOURCE, - }; - struct RenderGraphIndices { static constexpr uint32_t WORLD = 0; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index b531e707..6ac941f9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -19,7 +19,6 @@ of DigiPen Institute of Technology is prohibited. #include "Camera/SHCameraSystem.h" #include "Editor/SHEditor.h" #include "ECS_Base/Managers/SHSystemManager.h" -//#include "SHRenderer.h" #include "Graphics/Windowing/SHWindow.h" #include "Graphics/MiddleEnd/PerFrame/SHPerFrameData.h" #include "Graphics/MiddleEnd/Interface/SHViewport.h" @@ -125,25 +124,6 @@ namespace SHADE SHFreetypeInstance::Init(); - SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_VS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDraw_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/DebugDrawMesh_VS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/Normals_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_Tile_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_Tile_VS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_VS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false); - SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false); - // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); @@ -173,16 +153,6 @@ namespace SHADE auto windowDims = window->GetWindowSize(); auto cameraSystem = SHSystemManager::GetSystem(); - - // Set Up Cameras - //screenCamera = resourceManager.Create(); - //screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); - //screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); - - //worldCamera = resourceManager.Create(); - //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(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); - worldCameraDirector = cameraSystem->CreateDirector(); /*-----------------------------------------------------------------------*/ @@ -343,42 +313,6 @@ namespace SHADE // Generate render graph renderGraph->Generate(); -#if 0 - /*-----------------------------------------------------------------------*/ - /* SCREEN RENDER GRAPH */ - /*-----------------------------------------------------------------------*/ - // Initialize screen render graph - screenRenderGraph = resourceManager.Create(); - screenRenderGraph->Init("Screen Render Graph", device, swapchain, &resourceManager); - screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Scene"); - screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Entity ID"); - screenRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); - - auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID"}, {}); - auto uiSubpass = screenSpaceNode->AddSubpass("UI"); - uiSubpass->AddColorOutput("Scene"); - uiSubpass->AddColorOutput("Entity ID"); - uiSubpass->AddExteriorDrawCalls([=](Handle& cmdBuffer, uint32_t frameIndex) - { - textRenderingSubSystem->Render(cmdBuffer, frameIndex); - }); - -#ifdef SHEDITOR - { - // 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"); - } - -#else - screenRenderGraph->AddRenderToSwapchainNode("Scene", "Present", {"Screen Space Pass"}, {renderToSwapchainVS, renderToSwapchainFS}); -#endif - - screenRenderGraph->Generate(); - -#endif - // Create debug draw pipeline debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, false); SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawPipeline->GetVkPipeline(), "[Pipeline] Debug Draw"); @@ -412,11 +346,6 @@ namespace SHADE InitRenderGraph(); -#if 0 - #ifdef SHEDITOR - InitEditorRenderGraph(); - #endif -#endif // Create Semaphore for (auto& semaHandle : graphSemaphores) @@ -480,38 +409,6 @@ namespace SHADE defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } -#if 0 - #ifdef SHEDITOR - void SHGraphicsSystem::InitEditorRenderGraph(void) noexcept - { - auto windowDims = window->GetWindowSize(); - - // Create Default Viewport - editorViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 1.0f)); - - // Get render graph from viewport editor renderer - editorRenderGraph = resourceManager.Create(); - - std::vector> renderContextCmdPools{ swapchain->GetNumImages() }; - for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) - renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0]; - - editorRenderGraph->Init("Editor Render Graph", device, swapchain, &resourceManager); - editorRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); - - - auto imguiNode = editorRenderGraph->AddNode("ImGui Node", { "Present"}, {}); - auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); - imguiSubpass->AddColorOutput("Present"); - - // Generate world render graph - editorRenderGraph->Generate(); - - // Add world renderer to default viewport - editorRenderer = AddRenderer(SHRenderer::PROJECTION_TYPE::PERSPECTIVE); - } - #endif -#endif /*---------------------------------------------------------------------------------*/ /* Constructor/Destructors */ @@ -632,99 +529,15 @@ namespace SHADE renderGraph->Execute(frameIndex, descPool); renderGraph->End(frameIndex); -#if 0 - // For every viewport - for (int vpIndex = 0; vpIndex < static_cast(viewports.size()); ++vpIndex) - { - auto& renderers = viewports[vpIndex]->GetRenderers(); + graphicsQueue->SubmitCommandBuffer + ( + { renderGraph->GetCommandBuffer(frameIndex) }, + { frameData.semRenderFinishHdl }, + { frameData.semImgAvailableHdl }, + { vk::PipelineStageFlagBits::eColorAttachmentOutput }, + { frameData.fenceHdl } + ); - // For every renderer - for (int renIndex = 0; renIndex < static_cast(renderers.size()); ++renIndex) - { - /*-----------------------------------------------------------------------*/ - /* Renderer start */ - /*-----------------------------------------------------------------------*/ - // get command buffer of the renderer in the current frame - auto currentCmdBuffer = renderers[renIndex]->GetCommandBuffer(frameIndex); - - // Begin recording the command buffer - currentCmdBuffer->BeginRecording(); - - //// set viewport and scissor - //uint32_t w = static_cast(viewports[vpIndex]->GetWidth()); - //uint32_t h = static_cast(viewports[vpIndex]->GetHeight()); - //currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); - - // Force set the pipeline layout - currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); - currentCmdBuffer->ForceSetPipelineLayout(SHPredefinedData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE); - - // Bind all the buffers required for meshes - for (auto& [buffer, bindingPoint] : MESH_DATA) - { - if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer) - currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0); - else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer) - currentCmdBuffer->BindIndexBuffer(buffer, 0); - } - - lightingSubSystem->BindDescSet(currentCmdBuffer, frameIndex); - - // Bind textures - auto textureDescSet = texLibrary.GetTextureDescriptorSetGroup(); - if (textureDescSet) - { - std::array texDynamicOffset {0}; - currentCmdBuffer->BindDescriptorSet - ( - textureDescSet, - SH_PIPELINE_TYPE::GRAPHICS, - 0, - texDynamicOffset - ); - } - - // bind camera data - //renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); - -//#ifdef SHEDITOR -// if (renderers[renIndex] == worldRenderer) -// { -// auto editorSystem = SHSystemManager::GetSystem(); -// if (editorSystem->editorState != SHEditor::State::PLAY) -// worldRenderer->UpdateDataManual(currentCmdBuffer, frameIndex, cameraSystem->GetEditorCamera()->GetViewMatrix(), cameraSystem->GetEditorCamera()->GetProjMatrix(), cameraSystem->GetEditorCamera()->GetOrthoMatrix()); -// else -// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -// } -// else -// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -//#else -// renderers[renIndex]->UpdateDataAndBind(currentCmdBuffer, frameIndex); -//#endif - - // Draw the scene - renderers[renIndex]->Draw(frameIndex, descPool); - - // End the command buffer recording - currentCmdBuffer->EndRecording(); - /*-----------------------------------------------------------------------*/ - /* Renderer end */ - /*-----------------------------------------------------------------------*/ - - // submit a command buffer from the current render graph and make it wait for the previous render graph before submitting it to GPU. - graphicsQueue->SubmitCommandBuffer - ( - { currentCmdBuffer }, - { (vpIndex == viewports.size() - 1 && renIndex == renderers.size() - 1) ? frameData.semRenderFinishHdl : graphSemaphores[!semIndex] }, - { (vpIndex == 0 && renIndex == 0) ? frameData.semImgAvailableHdl : graphSemaphores[semIndex] }, - { vk::PipelineStageFlagBits::eColorAttachmentOutput }, - { (vpIndex == viewports.size() - 1 && renIndex == renderers.size() - 1) ? frameData.fenceHdl : Handle{} } - ); - - semIndex = !semIndex; - } - } -#endif } @@ -1023,7 +836,7 @@ namespace SHADE void SHGraphicsSystem::BuildFonts(void) noexcept { - fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); + fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); } #pragma endregion ADD_REMOVE @@ -1181,26 +994,18 @@ namespace SHADE renderGraph->HandleResize(resizeWidth, resizeHeight); #ifdef SHEDITOR - // NOTE: These 2 lines are actually not necessary because the editor viewport is not even used for // setting dynamic viewport or scissor state. ImGUI takes care of that for us. //editorViewport->SetWidth(windowDims.first); //editorViewport->SetHeight(windowDims.second); - - //editorRenderGraph->HandleResize(windowDims.first, windowDims.second); #endif - //screenRenderGraph->HandleResize(resizeWidth, resizeHeight); - mousePickSubSystem->HandleResize(); postOffscreenRenderSubSystem->HandleResize(); worldViewport->SetWidth(static_cast(resizeWidth)); worldViewport->SetHeight(static_cast(resizeHeight)); - //worldCamera->SetPerspective(90.0f, static_cast(resizeWidth), static_cast(resizeHeight), 0.0f, 100.0f); - //screenCamera->SetOrthographic(static_cast(resizeWidth), static_cast(resizeHeight), 0.01f, 100.0f); - auto cameraSystem = SHSystemManager::GetSystem(); #ifdef SHEDITOR cameraSystem->GetEditorCamera()->SetWidth(static_cast(resizeWidth)); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 0aa83f21..945db2d9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -51,7 +51,6 @@ namespace SHADE class SHVkFramebuffer; class SHVkCommandBuffer; class SHViewport; - class SHCamera; class SHVkShaderModule; class SHMaterial; class SHMaterialInstance; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp index 8e7dbd0f..3e944a5f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp @@ -100,7 +100,7 @@ namespace SHADE auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); return pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - mappings.at (SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + mappings.at (SHPredefinedDescriptorTypes::MATERIALS), //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, vk::ShaderStageFlagBits::eFragment diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp index 6a1f235e..1506cf71 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp @@ -81,7 +81,7 @@ namespace SHADE { return baseMaterial->GetPipeline()->GetPipelineLayout()->GetShaderBlockInterface ( - SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), + SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::MATERIALS), //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, vk::ShaderStageFlagBits::eFragment diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index b1508ce7..f1d4dc7f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -36,7 +36,7 @@ namespace SHADE //for (uint32_t i = 0; i < commandBuffers.size(); ++i) // commandBuffers[i] = cmdPools[i]->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); - cameraDescriptorSet = descriptorPool->Allocate(SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA), { 1 }); + cameraDescriptorSet = descriptorPool->Allocate(SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA), { 1 }); #ifdef _DEBUG const auto& CAM_DESC_SETS = cameraDescriptorSet->GetVkHandle(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 93e80cb0..ddacf3a7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -386,7 +386,7 @@ namespace SHADE std::fill (variableSizes.begin(), variableSizes.end(), 1); // Create the descriptor set - lightingDataDescSet = descPool->Allocate({ SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::LIGHTS) }, variableSizes); + lightingDataDescSet = descPool->Allocate({ SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::LIGHTS) }, variableSizes); #ifdef _DEBUG const auto& CAM_DESC_SETS = lightingDataDescSet->GetVkHandle(); for (int i = 0; i < static_cast(CAM_DESC_SETS.size()); ++i) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index 3a0110a4..ffd5ac96 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -178,9 +178,9 @@ namespace SHADE { auto& textRendererComps = SHComponentManager::GetDense(); auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::TEXT_RENDERING); - uint32_t fontSetIndex = mappings.at(SHGraphicsConstants::DescriptorSetTypes::FONT); - uint32_t staticGlobalSetIndex = mappings.at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA); - uint32_t cameraSetIndex = mappings.at(SHGraphicsConstants::DescriptorSetTypes::CAMERA); + uint32_t fontSetIndex = mappings.at(SHPredefinedDescriptorTypes::FONT); + uint32_t staticGlobalSetIndex = mappings.at(SHPredefinedDescriptorTypes::STATIC_DATA); + uint32_t cameraSetIndex = mappings.at(SHPredefinedDescriptorTypes::CAMERA); for (auto& comp : textRendererComps) { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index 9df14eba..0578e7a2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -168,7 +168,7 @@ namespace SHADE } texDescriptors = descPool->Allocate ( - { SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA) }, + { SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA) }, { static_cast(texOrder.size()) } ); #ifdef _DEBUG diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index a24f8968..67cc9112 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -646,7 +646,7 @@ namespace SHADE for (auto& node : nodes) { // bind static global data - SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA)); node->Execute(cmdBuffer, descPool, frameIndex); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 01363e6b..b8185176 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -359,10 +359,10 @@ namespace SHADE commandBuffer->ForceSetPipelineLayout(SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).dummyPipelineLayout, SH_PIPELINE_TYPE::COMPUTE); // bind static global data - SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA)); + SHGlobalDescriptorSets::BindStaticGlobalData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::STATIC_DATA)); // bind lighting data - SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::LIGHTS), frameIndex); + SHGlobalDescriptorSets::BindLightingData(commandBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::LIGHTS), frameIndex); } // Execute all subpass computes diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index c295d93b..cfc8443c 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -53,7 +53,7 @@ namespace SHADE //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 = layouts[descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE)]; + auto const& graphResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE)]; // Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE) for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) @@ -66,11 +66,11 @@ namespace SHADE } // check if all layouts are there - if (layouts.size() == descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) + if (layouts.size() == descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1) { // create compute resources computeResource = graphStorage->resourceHub->Create(); - auto computeResourceLayout = layouts[descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; + auto computeResourceLayout = layouts[descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)]; computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 }); #ifdef _DEBUG for (auto set : computeResource->descSet->GetVkHandle()) @@ -98,17 +98,17 @@ namespace SHADE // bind render graph resource - cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {}); + cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE), {}); // bind compute resource if (computeResource) { - cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]); + cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]); } // bind camera data if (renderer) - renderer->BindDescriptorSet (cmdBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + renderer->BindDescriptorSet (cmdBuffer, SH_PIPELINE_TYPE::COMPUTE, descMappings.at(SHPredefinedDescriptorTypes::CAMERA), frameIndex); // dispatch compute cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1); @@ -121,7 +121,7 @@ namespace SHADE void SHRenderGraphNodeCompute::HandleResize(void) noexcept { // We need to get from mappings because we want the introspected layout from the vector of layouts (of which the first few are predefined) - uint32_t RENDER_GRAPH_RESOURCE_SET_INDEX = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).at (SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE); + uint32_t RENDER_GRAPH_RESOURCE_SET_INDEX = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::RENDER_GRAPH_NODE_COMPUTE).at (SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE); // Since the descriptor set is standalone, the index we want to use is not the one in the shaders, it should always be 0. uint32_t RENDER_GRAPH_RESOURCE_UPDATE_SET_INDEX = 0; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index ce7e1622..5a34fa04 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -262,11 +262,13 @@ namespace SHADE void SHRenderGraphResource::HandleResize(uint32_t newWidth, uint32_t newHeight) noexcept { - width = newWidth; - height = newHeight; if ((resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) == 0) { + width = newWidth; + height = newHeight; + + // prepare image view details SHImageViewDetails viewDetails { @@ -287,6 +289,9 @@ namespace SHADE } else { + width = graphStorage->swapchain->GetWidth(); + height = graphStorage->swapchain->GetHeight(); + // Prepare image view details SHImageViewDetails viewDetails { diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index c903553b..88d375ce 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -227,7 +227,7 @@ namespace SHADE auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); if (renderer) - renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHGraphicsConstants::DescriptorSetTypes::CAMERA), frameIndex); + renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::CAMERA), frameIndex); // Draw all the batches superBatch->Draw(commandBuffer, frameIndex); diff --git a/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.cpp b/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.cpp index 40f917a0..eab4a03d 100644 --- a/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.cpp +++ b/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.cpp @@ -347,4 +347,14 @@ namespace SHADE return vkDepthFormat; } + uint32_t SHVkSwapchain::GetWidth(void) const noexcept + { + return width; + } + + uint32_t SHVkSwapchain::GetHeight(void) const noexcept + { + return height; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h b/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h index 384665d3..f3f51423 100644 --- a/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h +++ b/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h @@ -101,6 +101,8 @@ namespace SHADE vk::SwapchainKHR const& GetVkSwapchain (void) const noexcept; vk::SurfaceFormatKHR GetSurfaceFormatKHR (void) const noexcept; vk::Format GetDepthFormat (void) const noexcept; + uint32_t GetWidth (void) const noexcept; + uint32_t GetHeight (void) const noexcept; }; } diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index ee02478a..9a82577a 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -266,7 +266,7 @@ namespace SHADE { auto fragShader = SHResourceManager::LoadOrGet(spec.fragShader); auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); - auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); + auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); int const varCount = static_cast(interface->GetVariableCount()); for (int i = 0; i < varCount; ++i) From abf9c6b81374347cedf62f1604592a84e63caea4 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 29 Dec 2022 23:46:22 +0800 Subject: [PATCH 15/24] Refactored SHExecUtilities to return additional data --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 11 +- .../src/Tools/Utilities/SHExecUtilities.cpp | 161 ++++++++++++++---- .../src/Tools/Utilities/SHExecUtilities.h | 57 ++++++- 3 files changed, 184 insertions(+), 45 deletions(-) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index b4f893d7..ea4970a9 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -190,8 +190,9 @@ namespace SHADE oss << "[ScriptEngine] Building " << (debug ? " debug " : "") << "Managed Script Assembly (" << MANAGED_SCRIPT_LIB_NAME << ")!"; SHLOG_INFO(oss.str()); oss.str(""); - const bool BUILD_SUCCESS = SHExecUtilties::ExecBlockingCommand(generateBuildCommand(debug)) == 0; - if (BUILD_SUCCESS) + const auto BUILD_SUCCESS = SHExecUtilties::ExecBlockingProcess(L"C:\\Program Files\\dotnet\\dotnet.exe", generateBuildCommand(debug), true, true); + SHLOG_WARNING("Build Output: {}", SHStringUtilities::WstrToStr(BUILD_SUCCESS.StdOutput)); + if (BUILD_SUCCESS.Code == 0) { // Copy to built dll to the working directory and replace if (!copyFile("./tmp/SHADE_Scripting.dll", "SHADE_Scripting.dll", std::filesystem::copy_options::overwrite_existing)) @@ -235,7 +236,7 @@ namespace SHADE LoadScriptAssembly(); } - return BUILD_SUCCESS; + return BUILD_SUCCESS.Code == 0; } void SHScriptEngine::GenerateScriptsCsProjFile(const std::filesystem::path& path) const @@ -626,9 +627,9 @@ namespace SHADE std::wstring SHScriptEngine::generateBuildCommand(bool debug) { std::wostringstream oss; - oss << "dotnet build \"" << SHStringUtilities::StrToWstr(CSPROJ_PATH) << "\" -c "; + oss << " build \"" << SHStringUtilities::StrToWstr(std::filesystem::absolute(CSPROJ_PATH).string()) << "\" -c "; oss << debug ? "Debug" : "Release"; - oss << " -o \"./tmp/\" -fl -flp:LogFile=build.log;Verbosity=quiet -r \"win-x64\""; + oss << " -o \"./tmp/\" -r \"win-x64\""; return oss.str(); } } diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp index c1bae764..f3f6334d 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp @@ -23,44 +23,32 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ PROCESS_INFORMATION SHExecUtilties::ExecProcess(const std::wstring& path, const std::wstring& args) { - STARTUPINFOW startInfo; - PROCESS_INFORMATION procInfo; - ZeroMemory(&startInfo, sizeof(startInfo)); - ZeroMemory(&procInfo, sizeof(procInfo)); - startInfo.cb = sizeof(startInfo); - - std::wstring argsWstr = args; - - // Start Process - const auto SUCCESS = CreateProcess - ( - path.data(), argsWstr.data(), - nullptr, nullptr, false, NULL, nullptr, nullptr, - &startInfo, &procInfo - ); - - // Error Check - if (!SUCCESS) - { - auto err = GetLastError(); - std::ostringstream oss; - oss << "[SHExecUtilties] Failed to launch process. Error code: " << std::hex << err - << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; - throw std::runtime_error(oss.str()); - } - - return procInfo; + return execProcess(path, args, nullptr, nullptr); } - DWORD SHExecUtilties::ExecBlockingProcess(const std::wstring& path, const std::wstring& args) + ExecResult SHExecUtilties::ExecBlockingProcess(const std::wstring& path, const std::wstring& args, bool output, bool errorOutput) { - PROCESS_INFORMATION procInfo = ExecProcess(path, args); + // Create pipes for stdout and stderr if specified + HANDLE stdoutReadPipe = nullptr; + HANDLE stdoutWritePipe = nullptr; + HANDLE stderrReadPipe = nullptr; + HANDLE stderrWritePipe = nullptr; + if (output) + { + std::tie(stdoutReadPipe, stdoutWritePipe) = createIoPipes(); + } + if (errorOutput) + { + std::tie(stderrReadPipe, stderrWritePipe) = createIoPipes(); + } + + PROCESS_INFORMATION procInfo = execProcess(path, args, stdoutWritePipe, stderrWritePipe); // Wait for execution to end - DWORD status; + ExecResult result; while (true) { - const auto EXEC_SUCCESS = GetExitCodeProcess(procInfo.hProcess, &status); + const auto EXEC_SUCCESS = GetExitCodeProcess(procInfo.hProcess, &result.Code); if (!EXEC_SUCCESS) { auto err = GetLastError(); @@ -71,11 +59,24 @@ namespace SHADE } // Break only if process ends - if (status != STILL_ACTIVE) + if (result.Code != STILL_ACTIVE) { + // Get stdout/stderror output + if (stdoutReadPipe) + { + readPipeData(stdoutReadPipe, stdoutWritePipe, result.StdOutput); + } + if (stderrReadPipe) + { + readPipeData(stderrReadPipe, stderrWritePipe, result.StdErrOutput); + } + + // Close the process and threads for that process CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread); - return status; + + // Return results + return result; } } } @@ -92,12 +93,102 @@ namespace SHADE ); } - DWORD SHExecUtilties::ExecBlockingCommand(const std::wstring& command) + ExecResult SHExecUtilties::ExecBlockingCommand(const std::wstring& command, bool output, bool errorOutput) { return ExecBlockingProcess ( L"C:\\Windows\\system32\\cmd.exe", - L"/K \"" + command + L" & exit\"" + L"/K \"" + command + L" & exit\"", + output, + errorOutput ); } + + PROCESS_INFORMATION SHExecUtilties::execProcess(const std::wstring& path, const std::wstring& args, HANDLE outputWritePipe, HANDLE errorOutputWritePipe) + { + STARTUPINFOW startInfo; + PROCESS_INFORMATION procInfo; + ZeroMemory(&startInfo, sizeof(startInfo)); + ZeroMemory(&procInfo, sizeof(procInfo)); + startInfo.cb = sizeof(startInfo); + if (outputWritePipe) + { + startInfo.hStdOutput = outputWritePipe; + startInfo.dwFlags |= STARTF_USESTDHANDLES; + startInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + } + if (errorOutputWritePipe) + { + startInfo.hStdError = errorOutputWritePipe; + startInfo.dwFlags |= STARTF_USESTDHANDLES; + startInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + } + + std::wstring argsWstr = args; + + // Start Process + const auto SUCCESS = CreateProcess + ( + path.data(), argsWstr.data(), + nullptr, nullptr, true, NULL, nullptr, nullptr, + &startInfo, &procInfo + ); + + // Error Check + if (!SUCCESS) + { + auto err = GetLastError(); + std::ostringstream oss; + oss << "[SHExecUtilties] Failed to launch process. Error code: " << std::hex << err + << " (" << SHStringUtilities::GetWin32ErrorMessage(err) << ")"; + throw std::runtime_error(oss.str()); + } + + return procInfo; + } + + std::pair SHExecUtilties::createIoPipes() + { + SECURITY_ATTRIBUTES saAttr; + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = true; + saAttr.lpSecurityDescriptor = nullptr; + + // First: Read | Second: Write + std::pair output = { nullptr, nullptr }; + if (CreatePipe(&output.first, &output.second, &saAttr, 0)) + { + if (!SetHandleInformation(output.first, HANDLE_FLAG_INHERIT, 0)) + { + SHLOG_ERROR("[SHExecUtilities] Failed to initialize pipe for process IO."); + CloseHandle(output.first); + CloseHandle(output.second); + output = { nullptr, nullptr }; + } + } + else + { + SHLOG_ERROR("[SHExecUtilities] Failed to create pipe for process IO."); + } + + return output; + } + + void SHExecUtilties::readPipeData(HANDLE readPipe, HANDLE writePipe, std::wstring& output) + { + CloseHandle(writePipe); + + LARGE_INTEGER stdoutSize = {}; + while (true) + { + std::array buffer{}; + DWORD bytesRead = 0; + const auto RESULT = ReadFile(readPipe, buffer.data(), buffer.size(), &bytesRead, nullptr); // Blocking call here? + if (!RESULT || bytesRead <= 0) + break; + output.insert(output.end(), buffer.data(), buffer.data() + bytesRead); + } + + CloseHandle(readPipe); + } } diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h index 838cee41..9c5f38eb 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h @@ -17,6 +17,16 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { + /// + /// Stores the result of an execution of a process. + /// + struct SH_API ExecResult final + { + DWORD Code; + std::wstring StdOutput; + std::wstring StdErrOutput; + }; + /// /// Static class containing functions for executing external processes or commands. /// @@ -43,11 +53,13 @@ namespace SHADE /// /// Path to the processs to start. /// Arguments to pass to the process. + /// If true, stdout will be routed to return. + /// If true, outstderr will be routed to return. /// Return value of the process. /// /// Thrown if failed to start the process. /// - static DWORD ExecBlockingProcess(const std::wstring& path, const std::wstring& args); + static ExecResult ExecBlockingProcess(const std::wstring& path, const std::wstring& args, bool output = false, bool errorOutput = false); /*---------------------------------------------------------------------------------*/ /* Command Execution Functions */ @@ -69,16 +81,51 @@ namespace SHADE /// executing. /// /// Command to execute. + /// If true, stdout will be routed to return. + /// If true, outstderr will be routed to return. /// Return value of the process. /// /// Thrown if failed to start the process. /// - static DWORD ExecBlockingCommand(const std::wstring& command); + static ExecResult ExecBlockingCommand(const std::wstring& command, bool output = false, bool errorOutput = false); + + /*---------------------------------------------------------------------------------*/ + /* PowerShell Execution Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Executes a specified command in PowerShell. + /// This call does not wait for the command to finish executing. + /// + /// Command to execute. + /// + /// Information about the started cmd process that executes the command. + /// + /// + /// Thrown if failed to start the process. + /// + static PROCESS_INFORMATION ExecPowerShellCommand(const std::wstring& command); + /// + /// Executes a specified command in PowerShell and waits for that process to finish + /// executing. + /// + /// Command to execute. + /// Return value of the process. + /// + /// Thrown if failed to start the process. + /// + static DWORD ExecBlockingPowerShellCommand(const std::wstring& command); private: - /*-------------------------------------------------------------------------------*/ - /* Constructors/Destructors */ - /*-------------------------------------------------------------------------------*/ + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructors */ + /*---------------------------------------------------------------------------------*/ SHExecUtilties() = delete; + + /*---------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*---------------------------------------------------------------------------------*/ + static PROCESS_INFORMATION execProcess(const std::wstring& path, const std::wstring& args, HANDLE outputWritePipe, HANDLE errorOutputWritePipe); + static std::pair createIoPipes(); + static void readPipeData(HANDLE readPipe, HANDLE writePipe, std::wstring& output); }; } From 2f5d855fc64bc29b5a3157ce7e6f3f18f5b18b92 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 29 Dec 2022 23:46:44 +0800 Subject: [PATCH 16/24] Added stub for SHVSUtiltiies --- SHADE_Engine/src/Scripting/SHVSUtilities.cpp | 26 +++++++++++ SHADE_Engine/src/Scripting/SHVSUtilities.h | 45 ++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 SHADE_Engine/src/Scripting/SHVSUtilities.cpp create mode 100644 SHADE_Engine/src/Scripting/SHVSUtilities.h diff --git a/SHADE_Engine/src/Scripting/SHVSUtilities.cpp b/SHADE_Engine/src/Scripting/SHVSUtilities.cpp new file mode 100644 index 00000000..f2fdc0a0 --- /dev/null +++ b/SHADE_Engine/src/Scripting/SHVSUtilities.cpp @@ -0,0 +1,26 @@ +/************************************************************************************//*! +\file SHVSUtilities.cpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Dec 21, 2022 +\brief Contains the implementation for SHVSUtilities static class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include +// Primary Header +#include "SHVSUtilities.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*-----------------------------------------------------------------------------------*/ + std::filesystem::path SHVSUtilties::getDevEnvPath() + { + return {}; + } +} diff --git a/SHADE_Engine/src/Scripting/SHVSUtilities.h b/SHADE_Engine/src/Scripting/SHVSUtilities.h new file mode 100644 index 00000000..52a83e22 --- /dev/null +++ b/SHADE_Engine/src/Scripting/SHVSUtilities.h @@ -0,0 +1,45 @@ +/************************************************************************************//*! +\file SHVSUtilties.h +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Dec 21, 2022 +\brief Contains the interface for SHVSUtilties class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ + +// STL Includes +#include +// External Dependencies +#include + +namespace SHADE +{ + /// + /// Static class containing functions for working with Visual Studio installation and + /// running instances. + /// + class SH_API SHVSUtilties final + { + public: + + + private: + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructors */ + /*---------------------------------------------------------------------------------*/ + SHVSUtilties() = delete; + + /*---------------------------------------------------------------------------------*/ + /* Static Data Members */ + /*---------------------------------------------------------------------------------*/ + static std::filesystem::path devEnvPath; + + /*---------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*---------------------------------------------------------------------------------*/ + static std::filesystem::path getDevEnvPath(); + }; +} From ce16ca6f8d19b2d34a342f49fbd848aeca95f903 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 30 Dec 2022 15:29:17 +0800 Subject: [PATCH 17/24] Exposed transform and MDI buffers in SHBatch and exposed Batches in SHSuperBatch --- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 25 +++++++++++++++++++ .../src/Graphics/MiddleEnd/Batching/SHBatch.h | 4 ++- .../MiddleEnd/Batching/SHSuperBatch.h | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 77f7706e..7e4069f6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -586,6 +586,31 @@ namespace SHADE cmdBuffer->EndLabeledSegment(); } + /*-----------------------------------------------------------------------------------*/ + /* SHBatch - Getter Functions */ + /*-----------------------------------------------------------------------------------*/ + Handle SHBatch::GetTransformBuffer(uint32_t frameIndex) const noexcept + { + if (frameIndex >= transformDataBuffer.size()) + { + SHLOG_WARNING("[SHBatch] Attempted to retrieve a transform buffer of an invalid index."); + return {}; + } + + return transformDataBuffer[frameIndex]; + } + + Handle SHBatch::GetMDIBuffer(uint32_t frameIndex) const noexcept + { + if (frameIndex >= drawDataBuffer.size()) + { + SHLOG_WARNING("[SHBatch] Attempted to retrieve a MDI draw data buffer of an invalid index."); + return {}; + } + + return drawDataBuffer[frameIndex]; + } + /*---------------------------------------------------------------------------------*/ /* SHBatch - Helper Functions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h index dd4d33fd..d4ce068e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h @@ -94,6 +94,8 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ Handle GetPipeline() const noexcept { return pipeline; }; bool IsEmpty() const noexcept { return subBatches.empty(); } + Handle GetTransformBuffer(uint32_t frameIndex) const noexcept; + Handle GetMDIBuffer(uint32_t frameIndex) const noexcept; private: /*-----------------------------------------------------------------------------*/ @@ -122,7 +124,7 @@ namespace SHADE std::unique_ptr matPropsData; Byte matPropsDataSize = 0; Byte singleMatPropAlignedSize = 0; - Byte singleMatPropSize = 0; + Byte singleMatPropSize = 0; bool isCPUBuffersDirty = true; // GPU Buffers TripleBuffer drawDataBuffer; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h index 9877e04e..75bd1829 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h @@ -54,7 +54,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ void Add(const SHRenderable* renderable) noexcept; void Remove(const SHRenderable* renderable) noexcept; - void Clear() noexcept; + void Clear() noexcept; void UpdateBuffers(uint32_t frameIndex, Handle descPool); void Build(Handle device, Handle descPool, uint32_t frameIndex) noexcept; void Draw(Handle cmdBuffer, uint32_t frameIndex) noexcept; @@ -63,6 +63,7 @@ namespace SHADE /* Getter Functions */ /*-----------------------------------------------------------------------------*/ Handle GetSubpass() const noexcept { return subpass; }; + const std::vector& GetBatches() const noexcept { return batches; } private: /*-----------------------------------------------------------------------------*/ From 2e8535d3cfe17cf20653ba6191ecdf7b1935225e Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 30 Dec 2022 15:43:54 +0800 Subject: [PATCH 18/24] Fixed script building causing a freeze --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index ea4970a9..b17697ad 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -190,7 +190,7 @@ namespace SHADE oss << "[ScriptEngine] Building " << (debug ? " debug " : "") << "Managed Script Assembly (" << MANAGED_SCRIPT_LIB_NAME << ")!"; SHLOG_INFO(oss.str()); oss.str(""); - const auto BUILD_SUCCESS = SHExecUtilties::ExecBlockingProcess(L"C:\\Program Files\\dotnet\\dotnet.exe", generateBuildCommand(debug), true, true); + const auto BUILD_SUCCESS = SHExecUtilties::ExecBlockingProcess(L"C:\\Program Files\\dotnet\\dotnet.exe", generateBuildCommand(debug), false, false); SHLOG_WARNING("Build Output: {}", SHStringUtilities::WstrToStr(BUILD_SUCCESS.StdOutput)); if (BUILD_SUCCESS.Code == 0) { From 118ad33109f7c3fb88410f5ee1b84698955c9f6d Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 30 Dec 2022 15:54:45 +0800 Subject: [PATCH 19/24] Got rid of SHEnumWrapper --- .../GlobalData/SHGraphicsPredefinedData.cpp | 16 ++- .../GlobalData/SHGraphicsPredefinedData.h | 5 +- SHADE_Engine/src/Tools/SHEnumWrapper.h | 126 +++++++++--------- 3 files changed, 81 insertions(+), 66 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index a533249b..ffe29b36 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -198,12 +198,13 @@ namespace SHADE InitDummyPipelineLayouts (logicalDevice); } - std::vector> SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept + std::vector> SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes types) noexcept { std::vector> layoutsFound; for (uint8_t i = 0; i < numPredefinedDescSetLayoutTypes; ++i) { - if (types & (static_cast(1) << i)) + auto result = types & static_cast(static_cast(1) << i); + if (static_cast(result)) layoutsFound.push_back(predefinedLayouts[i]); } @@ -226,6 +227,17 @@ namespace SHADE return perSystemData[static_cast(systemType)].descMappings.GetMappings(); } + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator|(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept + { + return static_cast(static_cast(lhs) | static_cast(rhs)); + } + + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator&(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept + { + return static_cast(static_cast(lhs) & static_cast(rhs)); + + } + //SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetBatchingSystemData(void) noexcept //{ // return batchingSystemData; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index f46cb883..11bfc469 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -88,12 +88,15 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; + static std::vector> GetPredefinedDescSetLayouts (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes types) noexcept; static SHVertexInputState const& GetDefaultViState (void) noexcept; static PerSystem const& GetSystemData (SystemType systemType) noexcept; static SHDescriptorMappings::MapType const& GetMappings (SystemType systemType) noexcept; //static PerSystem const& GetBatchingSystemData(void) noexcept; //static PerSystem const& GetTextSystemData(void) noexcept; //static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept; + }; + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator| (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept; + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator& (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept; } diff --git a/SHADE_Engine/src/Tools/SHEnumWrapper.h b/SHADE_Engine/src/Tools/SHEnumWrapper.h index 7c37659e..07c92fab 100644 --- a/SHADE_Engine/src/Tools/SHEnumWrapper.h +++ b/SHADE_Engine/src/Tools/SHEnumWrapper.h @@ -2,66 +2,66 @@ #include -namespace SHADE -{ - template - class SHEnumWrapper - { - public: - using UnderlyingType = typename std::underlying_type_t; - - private: - UnderlyingType mask; - - public: - - constexpr SHEnumWrapper(void) noexcept - : mask{ 0 } - { - - }; - - constexpr SHEnumWrapper(BitType bit) noexcept - : mask{ static_cast(bit) } - { - - }; - - constexpr SHEnumWrapper(SHEnumWrapper const& rhs) noexcept = default; - constexpr SHEnumWrapper& operator= (SHEnumWrapper const& rhs) noexcept = default; - - constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept - : mask{ flags } - { - - }; - - constexpr SHEnumWrapper operator| (SHEnumWrapper const& rhs) const noexcept - { - return static_cast> (mask | rhs.mask); - }; - - constexpr SHEnumWrapper operator& (SHEnumWrapper const& rhs) const noexcept - { - return static_cast> (mask & rhs.mask); - }; - - constexpr operator UnderlyingType() const noexcept - { - return mask; - }; - }; - - template>> - inline BitType operator|(const BitType& left, const BitType& right) - { - return static_cast(static_cast(left) | static_cast(right)); - } - - template>> - inline BitType operator&(const BitType& left, const BitType& right) - { - return static_cast(static_cast(left) & static_cast(right)); - } - -} +//namespace SHADE +//{ +// template +// class SHEnumWrapper +// { +// public: +// using UnderlyingType = typename std::underlying_type_t; +// +// private: +// UnderlyingType mask; +// +// public: +// +// constexpr SHEnumWrapper(void) noexcept +// : mask{ 0 } +// { +// +// }; +// +// constexpr SHEnumWrapper(BitType bit) noexcept +// : mask{ static_cast(bit) } +// { +// +// }; +// +// constexpr SHEnumWrapper(SHEnumWrapper const& rhs) noexcept = default; +// constexpr SHEnumWrapper& operator= (SHEnumWrapper const& rhs) noexcept = default; +// +// constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept +// : mask{ flags } +// { +// +// }; +// +// constexpr SHEnumWrapper operator| (SHEnumWrapper const& rhs) const noexcept +// { +// return static_cast> (mask | rhs.mask); +// }; +// +// constexpr SHEnumWrapper operator& (SHEnumWrapper const& rhs) const noexcept +// { +// return static_cast> (mask & rhs.mask); +// }; +// +// constexpr operator UnderlyingType() const noexcept +// { +// return mask; +// }; +// }; +// +// template>> +// inline BitType operator|(const BitType& left, const BitType& right) +// { +// return static_cast(static_cast(left) | static_cast(right)); +// } +// +// template>> +// inline BitType operator&(const BitType& left, const BitType& right) +// { +// return static_cast(static_cast(left) & static_cast(right)); +// } +// +//} From 472f52af89811d23c6d41ef93889ebb0233665ae Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Fri, 30 Dec 2022 15:56:36 +0800 Subject: [PATCH 20/24] Should be finished for now, final checks to do --- SHADE_Engine/src/Input/SHInputManager.cpp | 244 +++++++++++----------- SHADE_Engine/src/Input/SHInputManager.h | 198 +++++++++++++----- 2 files changed, 272 insertions(+), 170 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index a1ebe1a6..cec78648 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -105,12 +105,12 @@ namespace SHADE //Write to lastKeys memcpy(keysLast, keys, sizeof(keys)); - //Poll + //Poll KB/M unsigned char keyboardState[MAX_KEYS] = {}; SecureZeroMemory(keyboardState, sizeof(keyboardState)); //if (GetKeyboardState(keyboardState) == false) return; bool keyboardStateGot = GetKeyboardState(keyboardState); - SHASSERT(keyboardStateGot, "SHInputManager:GetKeyboardState() failed ({})", GetLastError()); + SHASSERT(keyboardStateGot, "SHInputManager::GetKeyboardState() failed ({})", GetLastError()); keyCount = 0; keyToggleCount = 0; for (size_t i = 0; i < MAX_KEYS; ++i) @@ -449,27 +449,41 @@ namespace SHADE } //Bindings////////////////////////////////////////////////////////////////// - for (std::pair binding : bindings) + for (auto& binding : bindings) { SHLogicalBindingData& data = binding.second; - if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_X) + //Set last value + data.positiveInputHeldLast = data.positiveInputHeld; + data.negativeInputHeldLast = data.negativeInputHeld; + + //Reset held values + data.positiveInputHeld = false; + data.negativeInputHeld = false; + + if (data.bindingType == SHInputManager::SH_BINDINGTYPE::MOUSE_X) { double velX = 0.0; GetMouseVelocity(&velX, nullptr); + if (data.value > 0.0) data.positiveInputHeld = true; + else if (data.value < 0.0) data.negativeInputHeld = true; data.value = velX * data.sensitivity * (data.inverted ? -1.0 : 1.0); } - else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_Y) + else if (data.bindingType == SHInputManager::SH_BINDINGTYPE::MOUSE_Y) { double velY = 0.0; GetMouseVelocity(nullptr, &velY); + if (data.value > 0.0) data.positiveInputHeld = true; + else if (data.value < 0.0) data.negativeInputHeld = true; data.value = velY * data.sensitivity * (data.inverted ? -1.0 : 1.0); } - else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::MOUSE_SCROLL) + else if (data.bindingType == SHInputManager::SH_BINDINGTYPE::MOUSE_SCROLL) { + if (mouseWheelVerticalDelta > 0.0) data.positiveInputHeld = true; + else if (mouseWheelVerticalDelta < 0.0) data.negativeInputHeld = true; data.value = mouseWheelVerticalDelta * data.sensitivity * (data.inverted ? -1.0 : 1.0); } - else if (data.bindingType == SHLogicalBindingData::SH_BINDINGTYPE::KB_MB_CONTROLLER) + else if (data.bindingType == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER) { //Prioritise the largest magnitude double largestMagnitude = 0.0; @@ -477,27 +491,23 @@ namespace SHADE //If digital input was in, use sensitivity bool digitalInput = false; - //If data was read - bool positiveInputRead = false; - bool negativeInputRead = false; - //Over keycodes for (SH_KEYCODE k : data.positiveKeyCodes) { if (GetKey(k)) { - if (std::abs(1.0) > std::abs(largestMagnitude)) largestMagnitude = 1.0; + if (std::abs(1.0) > std::abs(largestMagnitude)) largestMagnitude = 1.0 * (data.inverted ? -1.0 : 1.0); digitalInput = true; - positiveInputRead = true; + data.positiveInputHeld = true; } } for (SH_KEYCODE k : data.negativeKeyCodes) { if (GetKey(k)) { - if (std::abs(-1.0) > std::abs(largestMagnitude)) largestMagnitude = -1.0; + if (std::abs(-1.0) > std::abs(largestMagnitude)) largestMagnitude = -1.0 * (data.inverted ? -1.0 : 1.0); digitalInput = true; - negativeInputRead = true; + data.negativeInputHeld = true; } } @@ -505,9 +515,10 @@ namespace SHADE for (SH_CONTROLLERCODE c : data.positiveControllerCodes) { double newValue = 0.0; - if (GetControllerInput(c, &newValue)) + GetControllerInput(c, &newValue); + if (std::abs(newValue) > std::abs(data.dead)) { - positiveInputRead = true; + data.positiveInputHeld = true; if (static_cast(c) < NUM_CONTROLLER_BUTTON) { digitalInput = true; @@ -520,9 +531,10 @@ namespace SHADE for (SH_CONTROLLERCODE c : data.negativeControllerCodes) { double newValue = 0.0; - if (GetControllerInput(c, &newValue)) + GetControllerInput(c, &newValue); + if (std::abs(newValue) > std::abs(data.dead)) { - negativeInputRead = true; + data.negativeInputHeld = true; if (static_cast(c) < NUM_CONTROLLER_BUTTON) { digitalInput = true; @@ -533,14 +545,14 @@ namespace SHADE } //If both positive and negative inputs read, do not modify value - if (positiveInputRead && negativeInputRead) + if (data.positiveInputHeld && data.negativeInputHeld) { data.value = data.value; } else { //If no data received, use gravity - if (!positiveInputRead && !negativeInputRead) + if (!data.positiveInputHeld && !data.negativeInputHeld) { if (data.value > 0.0) { @@ -555,28 +567,79 @@ namespace SHADE } else //Either positive OR negative input was read { - //If digital input was in, use sensitivity + //If digital input was in, + //sensitivity is used as a rate at which the axis value is changed if (digitalInput) { + //If the input is opposite the current value, gravity works + //with the sensitivity + if (data.value > 0.0 && largestMagnitude < 0.0) + data.value -= data.gravity * dt; + if (data.value < 0.0 && largestMagnitude > 0.0) + data.value += data.gravity * dt; + + //Moved by sensitivity data.value += data.sensitivity * largestMagnitude * dt; + if (data.value > 1.0) data.value = 1.0; else if (data.value < -1.0) data.value = -1.0; } + //If analog input was in, + //sensitivity is instead used as a multiplier else { - data.value = largestMagnitude; + data.value = largestMagnitude * data.sensitivity; + if (data.value > 1.0) data.value = 1.0; + else if (data.value < -1.0) data.value = -1.0; } if (data.snap) //Snapping { - if (data.value > 0.0 && negativeInputRead) + if (data.value > 0.0 && data.negativeInputHeld) data.value = 0.0; - if (data.value < 0.0 && positiveInputRead) + if (data.value < 0.0 && data.positiveInputHeld) data.value = 0.0; } } } } + + //Binding timings + + //Positivie bindings + if (data.positiveInputHeld) //Input is down + { + if (!data.positiveInputHeldLast) //Input was just pressed + { + data.positiveHeldTime = 0.0; //Reset timer + } + data.positiveHeldTime += dt; //Tick up + } + else //Input is up + { + if (data.positiveInputHeldLast) //Input was just released + { + data.positiveReleasedTime = 0.0; //Reset timer + } + data.positiveReleasedTime += dt; //Tick up + } + + if (data.negativeInputHeld) //Input is down + { + if (!data.negativeInputHeldLast) //Input was just pressed + { + data.negativeHeldTime = 0.0; //Reset timer + } + data.negativeHeldTime += dt; //Tick up + } + else //Input is up + { + if (data.negativeInputHeldLast) //Input was just released + { + data.negativeReleasedTime = 0.0; //Reset timer + } + data.negativeReleasedTime += dt; //Tick up + } } } @@ -710,8 +773,29 @@ namespace SHADE return bindings[bindingName].value; } + double SHInputManager::GetBindingAxisRaw(std::string const& bindingName, size_t cNum) noexcept + { + //Neutral if both positive and negative held + if (bindings[bindingName].positiveInputHeld && bindings[bindingName].negativeInputHeld) + { + return 0.0; + } + else if (bindings[bindingName].positiveInputHeld) + { + return 1.0; + } + else if (bindings[bindingName].negativeInputHeld) + { + return -1.0; + } + + //No input means neutral + return 0.0; + } + bool SHInputManager::GetBindingPositiveButton(std::string const& bindingName, size_t cNum) noexcept { + /* if (cNum >= XUSER_MAX_COUNT) return false; //Over keycodes @@ -726,11 +810,13 @@ namespace SHADE if (GetControllerInput(c, nullptr, nullptr, nullptr, cNum)) return true; } - return false; + return false;*/ + return bindings[bindingName].positiveInputHeld; } bool SHInputManager::GetBindingNegativeButton(std::string const& bindingName, size_t cNum) noexcept { + /* if (cNum >= XUSER_MAX_COUNT) return false; //Over keycodes @@ -745,11 +831,13 @@ namespace SHADE if (GetControllerInput(c, nullptr, nullptr, nullptr, cNum)) return true; } - return false; + return false;*/ + return bindings[bindingName].negativeInputHeld; } bool SHInputManager::GetBindingPositiveButtonDown(std::string const& bindingName, size_t cNum) noexcept { + /* if (cNum >= XUSER_MAX_COUNT) return false; //Over keycodes @@ -764,11 +852,13 @@ namespace SHADE if (GetControllerInputDown(c, nullptr, cNum)) return true; } - return false; + return false;*/ + return (bindings[bindingName].positiveInputHeld && !bindings[bindingName].positiveInputHeldLast); } bool SHInputManager::GetBindingNegativeButtonDown(std::string const& bindingName, size_t cNum) noexcept { + /* if (cNum >= XUSER_MAX_COUNT) return false; //Over keycodes @@ -783,11 +873,13 @@ namespace SHADE if (GetControllerInputDown(c, nullptr, cNum)) return true; } - return false; + return false;*/ + return (bindings[bindingName].negativeInputHeld && !bindings[bindingName].negativeInputHeldLast); } bool SHInputManager::GetBindingPositiveButtonUp(std::string const& bindingName, size_t cNum) noexcept { + /* if (cNum >= XUSER_MAX_COUNT) return false; //Over keycodes @@ -802,11 +894,13 @@ namespace SHADE if (GetControllerInputUp(c, nullptr, cNum)) return true; } - return false; + return false;*/ + return (!bindings[bindingName].positiveInputHeld && bindings[bindingName].positiveInputHeldLast); } bool SHInputManager::GetBindingNegativeButtonUp(std::string const& bindingName, size_t cNum) noexcept { + /* if (cNum >= XUSER_MAX_COUNT) return false; //Over keycodes @@ -821,93 +915,7 @@ namespace SHADE if (GetControllerInputUp(c, nullptr, cNum)) return true; } - return false; + return false;*/ + return (!bindings[bindingName].positiveInputHeld && bindings[bindingName].positiveInputHeldLast); } - - //Fetches longest hold time - double SHInputManager::GetBindingPositiveHeldTime(std::string const& bindingName, size_t cNum) noexcept - { - if (cNum >= XUSER_MAX_COUNT) return 0.0; - - double maxHeldTime = 0.0; - - //Over keycodes - for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes) - { - if (GetKeyHeldTime(k) > maxHeldTime) maxHeldTime = GetKeyHeldTime(k); - } - - //Over controller buttons - for (SH_CONTROLLERCODE c : bindings[bindingName].positiveControllerCodes) - { - if (GetControllerInputHeldTime(c, cNum) > maxHeldTime) maxHeldTime = GetControllerInputHeldTime(c); - } - - return maxHeldTime; - } - - double SHInputManager::GetBindingNegativeHeldTime(std::string const& bindingName, size_t cNum) noexcept - { - if (cNum >= XUSER_MAX_COUNT) return 0.0; - - double maxHeldTime = 0.0; - - //Over keycodes - for (SH_KEYCODE k : bindings[bindingName].negativeKeyCodes) - { - if (GetKeyHeldTime(k) > maxHeldTime) maxHeldTime = GetKeyHeldTime(k); - } - - //Over controller buttons - for (SH_CONTROLLERCODE c : bindings[bindingName].negativeControllerCodes) - { - if (GetControllerInputHeldTime(c, cNum) > maxHeldTime) maxHeldTime = GetControllerInputHeldTime(c); - } - - return maxHeldTime; - } - - //Fetches shortest release time - double SHInputManager::GetBindingPositiveReleasedTime(std::string const& bindingName, size_t cNum) noexcept - { - if (cNum >= XUSER_MAX_COUNT) return 0.0; - - double minReleaseTime = _HUGE_ENUF; - - //Over keycodes - for (SH_KEYCODE k : bindings[bindingName].positiveKeyCodes) - { - if (GetKeyReleasedTime(k) < minReleaseTime) minReleaseTime = GetKeyReleasedTime(k); - } - - //Over controller buttons - for (SH_CONTROLLERCODE c : bindings[bindingName].positiveControllerCodes) - { - if (GetControllerInputReleasedTime(c, cNum) < minReleaseTime) minReleaseTime = GetControllerInputReleasedTime(c); - } - - return minReleaseTime; - } - - double SHInputManager::GetBindingNegativeReleasedTime(std::string const& bindingName, size_t cNum) noexcept - { - if (cNum >= XUSER_MAX_COUNT) return 0.0; - - double minReleaseTime = _HUGE_ENUF; - - //Over keycodes - for (SH_KEYCODE k : bindings[bindingName].negativeKeyCodes) - { - if (GetKeyReleasedTime(k) < minReleaseTime) minReleaseTime = GetKeyReleasedTime(k); - } - - //Over controller buttons - for (SH_CONTROLLERCODE c : bindings[bindingName].negativeControllerCodes) - { - if (GetControllerInputReleasedTime(c, cNum) < minReleaseTime) minReleaseTime = GetControllerInputReleasedTime(c); - } - - return minReleaseTime; - } - } //namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index df996647..2b9a810f 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -300,20 +300,22 @@ namespace SHADE RIGHT_THUMBSTICK_Y }; + //BINDING TYPES/////////////////////////////////////////////////////////// + enum class SH_BINDINGTYPE + { + KB_MB_CONTROLLER, + MOUSE_X, + MOUSE_Y, + MOUSE_SCROLL + }; + private: /*------------------------------------------------------------------------*/ /* Struct for logical bindings */ /*------------------------------------------------------------------------*/ struct SH_API SHLogicalBindingData { - //BINDING TYPES/////////////////////////////////////////////////////////// - enum class SH_BINDINGTYPE - { - KB_MB_CONTROLLER, - MOUSE_X, - MOUSE_Y, - MOUSE_SCROLL - }; + //BINDINGS//////////////////////////////////////////////////////////////// @@ -337,6 +339,12 @@ namespace SHADE //The current value of the axis binding double value = 0.0; + bool positiveInputHeld = false; + bool negativeInputHeld = false; + + bool positiveInputHeldLast = false; + bool negativeInputHeldLast = false; + //Whether the input is inverted, //If so, positive bindings will make the value negative, // negative bindings will make the value positive, @@ -359,6 +367,18 @@ namespace SHADE //If enabled, axis value will reset to zero when pressing a button //that corresponds in the opposite direction bool snap = false; + + //How long the positive binding has been held for + double positiveHeldTime = 0.0; + + //How long the positive binding has been released for + double positiveReleasedTime = 0.0; + + //How long the negative binding has been held for + double negativeHeldTime = 0.0; + + //How long the negative binding has been released for + double negativeReleasedTime = 0.0; }; public: @@ -666,96 +686,144 @@ namespace SHADE /*------------------------------------------------------------------------*/ //Get a read-only map of the bindings - static inline std::map const& getBindings() noexcept + static inline std::map const& GetBindings() noexcept { return bindings; } //Add a new binding to the map - static inline void BindingsAdd(std::string const& newBindingName) noexcept + static inline void AddBinding(std::string const& newBindingName) noexcept { bindings.insert({ newBindingName, SHLogicalBindingData() }); } //Remove a binding and all its associated inputs from the list //Returns 1 if found and removed, 0 if not found - static inline size_t BindingsRemove(std::string const& bindingName) noexcept + static inline size_t RemoveBinding(std::string const& bindingName) noexcept { return bindings.erase(bindingName); } //Clears all bindings from the list - static inline void BindingsClear() noexcept + static inline void ClearBindings() noexcept { bindings.clear(); } //Get the number of bindings present - static inline size_t BindingsCount() noexcept + static inline size_t CountBindings() noexcept { return bindings.size(); } //BINDING VALUES//////////////////////////////////////////////////////////// - static inline bool BindingsGetInverted(std::string const& bindingName) + //Get whether the binding is inverted or not + //If inverted, positive inputs subtract the value of the binding + // negative inputs add to the value of the binding + // Moving mouse up / right will be negative + // Scrolling the mouse wheel up will be negative + static inline bool GetBindingInverted(std::string const& bindingName) { return bindings[bindingName].inverted; } - static inline void BindingsSetInverted(std::string const& bindingName, bool const newValue) + //Set whether the binding is inverted or not + //If inverted, positive inputs subtract the value of the binding + // negative inputs add to the value of the binding + // Moving mouse up / right will be negative + // Scrolling the mouse wheel up will be negative + static inline void SetBindingInverted(std::string const& bindingName, bool const newValue) { bindings[bindingName].inverted = newValue; } - static inline double BindingsGetGravity(std::string const& bindingName) + //Gets the gravity of the binding + //The rate at which the value moves to neutral if no input in the direction is read + //Should be non-negative + static inline double GetBindingGravity(std::string const& bindingName) { return bindings[bindingName].gravity; } - static inline void BindingsSetGravity(std::string const& bindingName, double const newValue) + //Sets the gravity of the binding + //The rate at which the value moves to neutral if no input in the direction is read + //Should be non-negative + static inline void SetBindingGravity(std::string const& bindingName, double const newValue) { bindings[bindingName].gravity = newValue; } - static inline double BindingsGetDead(std::string const& bindingName) + //Get the dead zone of the binding on a scale of 0 to 1, + //Any positive or negative analog input with magnitude less than this will be registered as neutral + //irrelvant for digital inputs + static inline double GetBindingDead(std::string const& bindingName) { return bindings[bindingName].dead; } - static inline void BindingsSetDead(std::string const& bindingName, double const newValue) + //Get the dead zone of the binding on a scale of 0 to 1, + //Any positive or negative analog input with magnitude less than this will be registered as neutral + //irrelvant for digital inputs + static inline void SetBindingDead(std::string const& bindingName, double const newValue) { bindings[bindingName].dead = newValue; } - static inline double BindingsGetSensitivity(std::string const& bindingName) + //Get the sensitivity of the binding + //Serves as a multiplier for mouse movement/scrolling + //For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative + //For other analog inputs, serves as a multiplier + static inline double GetBindingSensitivity(std::string const& bindingName) { return bindings[bindingName].sensitivity; } - static inline void BindingsSetSensitivity(std::string const& bindingName, double const newValue) + //Set the sensitivity of the binding + //Serves as a multiplier for mouse movement/scrolling + //For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative + //For other analog inputs, serves as a multiplier + static inline void SetBindingSensitivity(std::string const& bindingName, double const newValue) { bindings[bindingName].sensitivity = newValue; } - static inline bool BindingsGetSnap(std::string const& bindingName) + //Gets the snap of the binding + //If no other input on the axis is present and a input is made in the opposite direction of the current value, + //the binding's value will jump to neutral 0 before resuming in the input direction + static inline bool GetBindingSnap(std::string const& bindingName) { return bindings[bindingName].snap; } - static inline void BindingsSetSnap(std::string const& bindingName, bool const newValue) + //Sets the snap of the binding + //If no other input on the axis is present and a input is made in the opposite direction of the current value, + //the binding's value will jump to neutral 0 before resuming in the input direction + static inline void SetBindingSnap(std::string const& bindingName, bool const newValue) { bindings[bindingName].snap = newValue; } //BINDING TYPE////////////////////////////////////////////////////////////// - static inline SHLogicalBindingData::SH_BINDINGTYPE BindingsGetType(std::string const& bindingName) + //Get the type of the binding + //There are four types: + //KB_MB_CONTROLLER Binding is connected to the keyboard, mouse and controller buttons and its analog inputs + //MOUSE_X Binding is connected to horizontal movement of the mouse + //MOUSE_Y Binding is connected to the vertical movement of the mouse + //MOUSE_SCROLL Binding is connected to the scrolling of the mouse wheel + static inline SH_BINDINGTYPE GetBindingType(std::string const& bindingName) { return bindings[bindingName].bindingType; } - static inline void BindingsSetType(std::string const& bindingName, SHLogicalBindingData::SH_BINDINGTYPE const newType) + //Set the type of the binding + //There are four types: + //KB_MB_CONTROLLER Binding is connected to the keyboard, mouse and controller buttons and its analog inputs + //MOUSE_X Binding is connected to horizontal movement of the mouse + //MOUSE_Y Binding is connected to the vertical movement of the mouse + //MOUSE_SCROLL Binding is connected to the scrolling of the mouse wheel + static inline void SetBindingType(std::string const& bindingName, SH_BINDINGTYPE const newType) { bindings[bindingName].bindingType = newType; } @@ -763,13 +831,13 @@ namespace SHADE //POSITIVE KEYCODES///////////////////////////////////////////////////////// //Check positive keycodes to binding - static inline std::set const& BindingsGetPositiveKeyCodes(std::string const& bindingName) noexcept + static inline std::set const& GetBindingPositiveKeyCodes(std::string const& bindingName) noexcept { return bindings[bindingName].positiveKeyCodes; } //Add positive SH_KEYCODE to binding - static inline void BindingsAddPositiveKeyCode(std::string const& bindingName, + static inline void AddBindingPositiveKeyCode(std::string const& bindingName, SH_KEYCODE toAdd) noexcept { bindings[bindingName].positiveKeyCodes.insert(toAdd); @@ -777,14 +845,14 @@ namespace SHADE //Remove positive SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveKeyCode(std::string const& bindingName, + static inline size_t RemoveBindingPositiveKeyCode(std::string const& bindingName, SH_KEYCODE toRemove) noexcept { return bindings[bindingName].positiveKeyCodes.erase(toRemove); } //Clear all positive SH_KEYCODEs from binding - static inline void BindingsClearPositiveKeyCodes(std::string const& bindingName) noexcept + static inline void ClearBindingPositiveKeyCodes(std::string const& bindingName) noexcept { bindings[bindingName].positiveKeyCodes.clear(); } @@ -792,13 +860,13 @@ namespace SHADE //NEGATIVE KEYCODES///////////////////////////////////////////////////////// //Check negative keycodes to binding - static inline std::set const& BindingsGetNegativeKeyCodes(std::string const& bindingName) noexcept + static inline std::set const& GetBindingNegativeKeyCodes(std::string const& bindingName) noexcept { return bindings[bindingName].negativeKeyCodes; } //Add negative SH_KEYCODE to binding - static inline void BindingsAddNegativeKeyCode(std::string const& bindingName, + static inline void AddBindingNegativeKeyCode(std::string const& bindingName, SH_KEYCODE toAdd) noexcept { bindings[bindingName].negativeKeyCodes.insert(toAdd); @@ -806,14 +874,14 @@ namespace SHADE //Remove negative SH_KEYCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeKeyCode(std::string const& bindingName, + static inline size_t RemoveBindingNegativeKeyCode(std::string const& bindingName, SH_KEYCODE toRemove) noexcept { return bindings[bindingName].negativeKeyCodes.erase(toRemove); } //Clear all negative SH_KEYCODEs from binding - static inline void BindingsClearNegativeKeyCodes(std::string const& bindingName) noexcept + static inline void ClearBindingNegativeKeyCodes(std::string const& bindingName) noexcept { bindings[bindingName].negativeKeyCodes.clear(); } @@ -821,13 +889,13 @@ namespace SHADE //POSITIVE CONTROLLERCODES////////////////////////////////////////////////// //Check positive controllercodes to binding - static inline std::set const& BindingsGetPositiveControllerCodes(std::string const& bindingName) noexcept + static inline std::set const& GetBindingPositiveControllerCodes(std::string const& bindingName) noexcept { return bindings[bindingName].positiveControllerCodes; } //Add positive SH_CONTROLLERCODE to binding - static inline void BindingsAddPositiveControllerCode(std::string const& bindingName, + static inline void AddBindingPositiveControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toAdd) noexcept { bindings[bindingName].positiveControllerCodes.insert(toAdd); @@ -835,14 +903,14 @@ namespace SHADE //Remove positive SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemovePositiveControllerCode(std::string const& bindingName, + static inline size_t RemoveBindingPositiveControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toRemove) noexcept { return bindings[bindingName].positiveControllerCodes.erase(toRemove); } //Clear all positive SH_CONTROLLERCODEs from binding - static inline void BindingsClearPositiveControllerCodes(std::string const& bindingName) noexcept + static inline void ClearBindingPositiveControllerCodes(std::string const& bindingName) noexcept { bindings[bindingName].positiveControllerCodes.clear(); } @@ -850,13 +918,13 @@ namespace SHADE //NEGATIVE CONTROLLERCODES////////////////////////////////////////////////// //Check negative controllercodes to binding - static inline std::set const& BindingsGetNegativeControllerCodes(std::string const& bindingName) noexcept + static inline std::set const& GetBindingNegativeControllerCodes(std::string const& bindingName) noexcept { return bindings[bindingName].negativeControllerCodes; } //Add negative SH_CONTROLLERCODE to binding - static inline void BindingsAddNegativeControllerCode(std::string const& bindingName, + static inline void AddBindingNegativeControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toAdd) noexcept { bindings[bindingName].negativeControllerCodes.insert(toAdd); @@ -864,48 +932,74 @@ namespace SHADE //Remove negative SH_CONTROLLERCODE from binding //If toRemove found and removed, returns 1. Otherwise, 0. - static inline size_t BindingsRemoveNegativeControllerCode(std::string const& bindingName, + static inline size_t RemoveBindingNegativeControllerCode(std::string const& bindingName, SH_CONTROLLERCODE toRemove) noexcept { return bindings[bindingName].negativeControllerCodes.erase(toRemove); } //Clear all negative SH_CONTROLLERCODEs from binding - static inline void BindingsClearNegativeControllerCodes(std::string const& bindingName) noexcept + static inline void ClearBindingNegativeControllerCodes(std::string const& bindingName) noexcept { bindings[bindingName].negativeControllerCodes.clear(); } - //Get the axis value of binding, between -1 and 1 for non-mouse - //For mouse, it won't be between -1 and 1. It will also be multiplied by sensitivity + //Get the axis value of binding, between -1 and 1 for non-mouse movement/wheel + //For mouse movement/wheel, it won't be between -1 and 1. It will also be multiplied by sensitivity //To avoid interference between mouse movement/wheel and keyboard/mouse/controller input, //Set mouseXBound, mouseYBound and mouseScrollBound to false + //controllerNumber is not used static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + //Get the axis value of binding, which will be fixed among -1, 0 and 1 for non-mouse movement/wheel + //No difference between this and GetBindingAxis for mouse movement/wheel + //But for other inputs, does not consider smoothing options such as gravity and sensitivity + //If both positive and negative input is detected, returns neutral 0 + //controllerNumber is not used + static double GetBindingAxisRaw(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + //Whether binding is being held or not - //Does not work for mouse movement + //Does not work for mouse movement or wheel static bool GetBindingPositiveButton(std::string const& bindingName, size_t controllerNumber = 0) noexcept; static bool GetBindingNegativeButton(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is pressed down IN THIS FRAME ONLY - //Does not work for mouse movement + //Does not work for mouse movement or wheel static bool GetBindingPositiveButtonDown(std::string const& bindingName, size_t controllerNumber = 0) noexcept; static bool GetBindingNegativeButtonDown(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Whether binding is released IN THIS FRAME ONLY - //Does not work for mouse movement + //Does not work for mouse movement or wheel static bool GetBindingPositiveButtonUp(std::string const& bindingName, size_t controllerNumber = 0) noexcept; static bool GetBindingNegativeButtonUp(std::string const& bindingName, size_t controllerNumber = 0) noexcept; //Binding times - //Does not work for mouse movement - static double GetBindingPositiveHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; - static double GetBindingNegativeHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + //Gets how long the binding has been considered positive + //Does not work for mouse movement or wheel + static inline double GetBindingPositiveHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept + { + return bindings[bindingName].positiveHeldTime; + } + //Gets how long the binding has been considered negative + //Does not work for mouse movement or wheel + static inline double GetBindingNegativeHeldTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept + { + return bindings[bindingName].negativeHeldTime; + } - //Does not work for mouse movement - static double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; - static double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept; + //Gets how long the binding has been not considered positive + //Does not work for mouse movement or wheel + static inline double GetBindingPositiveReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept + { + return bindings[bindingName].positiveReleasedTime; + } + //Gets how long the binding has been not considered negative + //Does not work for mouse movement or wheel + static inline double GetBindingNegativeReleasedTime(std::string const& bindingName, size_t controllerNumber = 0) noexcept + { + return bindings[bindingName].negativeReleasedTime; + } /*------------------------------------------------------------------------*/ /* Other Functions */ From 8db5b35f252d563d65daa3c53484065944032b56 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 30 Dec 2022 17:00:48 +0800 Subject: [PATCH 21/24] Added additional file utilities, PowerShell based execution of commands and tools for working with visual studio --- Dependencies.bat | 11 +++++- Dependencies.lua | 3 +- SHADE_Engine/premake5.lua | 6 ++- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 16 +++++--- SHADE_Engine/src/Scripting/SHVSUtilities.cpp | 39 ++++++++++++++++++- SHADE_Engine/src/Scripting/SHVSUtilities.h | 9 ++++- .../src/Tools/Utilities/SHExecUtilities.cpp | 23 ++++++++++- .../src/Tools/Utilities/SHExecUtilities.h | 10 +++-- .../src/Tools/Utilities/SHFileUtilties.cpp | 20 ++++++++-- .../src/Tools/Utilities/SHFileUtilties.h | 35 ++++++++++------- 10 files changed, 136 insertions(+), 36 deletions(-) diff --git a/Dependencies.bat b/Dependencies.bat index ba411815..460a1d87 100644 --- a/Dependencies.bat +++ b/Dependencies.bat @@ -20,10 +20,11 @@ echo "M - SDL" echo "N - dotnet" echo "O - tinyddsloader" echo "P - fmod" +echo "Q - vswhere" echo --------------------------------------------------- echo. -choice /C ABCDEFGHIJKLMNOP /T 10 /D A +choice /C ABCDEFGHIJKLMNOPQ /T 10 /D A set _e=%ERRORLEVEL% if %_e%==1 goto VMA @@ -42,6 +43,7 @@ if %_e%==13 goto SDL if %_e%==14 goto dotnet if %_e%==15 goto tinyddsloader if %_e%==16 goto fmod +if %_e%==17 goto vswhere :VMA echo -----------------------VMA---------------------------- @@ -155,6 +157,13 @@ if %_e%==15 (goto :done) else (goto :fmod) echo --------------------fmod------------------------- rmdir "Dependencies/fmod" /S /Q git clone https://github.com/SHADE-DP/FMOD.git "Dependencies/fmod" +if %_e%==16 (goto :done) else (goto :vswhere) + +:vswhere +echo -----------------------vswhere---------------------------- +rmdir "Dependencies/vswhere" /S /Q +mkdir "Dependencies/vswhere" +powershell -Command "& {wget https://github.com/microsoft/vswhere/releases/download/3.1.1/vswhere.exe -OutFile "Dependencies/vswhere/vswhere.exe"}" :done echo DONE! diff --git a/Dependencies.lua b/Dependencies.lua index fe75c3f4..2694fe35 100644 --- a/Dependencies.lua +++ b/Dependencies.lua @@ -16,4 +16,5 @@ IncludeDir["SDL"] = "%{wks.location}\\Dependencies\\SDL" IncludeDir["VULKAN"] = "$(VULKAN_SDK)" IncludeDir["dotnet"] = "%{wks.location}\\Dependencies\\dotnet" IncludeDir["tinyddsloader"] = "%{wks.location}\\Dependencies\\tinyddsloader" -IncludeDir["fmod"] = "%{wks.location}\\Dependencies\\fmod" \ No newline at end of file +IncludeDir["fmod"] = "%{wks.location}\\Dependencies\\fmod" +IncludeDir["vswhere"] = "%{wks.location}\\Dependencies\\vswhere" \ No newline at end of file diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 7fb7291d..17ca5be8 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -124,7 +124,8 @@ project "SHADE_Engine" "xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Debug\\ModelCompiler.exe\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.FontCompiler}\\bin\\Debug\\FontCompiler.exe\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodL.dll\" \"$(OutDir)\"", - "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudioL.dll\" \"$(OutDir)\"" + "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudioL.dll\" \"$(OutDir)\"", + "xcopy /r /y /q \"%{IncludeDir.vswhere}\\vswhere.exe\" \"$(OutDir)\"" } filter "configurations:Release" @@ -134,7 +135,8 @@ project "SHADE_Engine" "xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Release\\ModelCompiler.exe\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.FontCompiler}\\bin\\Release\\FontCompiler.exe\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmod.dll\" \"$(OutDir)\"", - "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudio.dll\" \"$(OutDir)\"" + "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudio.dll\" \"$(OutDir)\"", + "xcopy /r /y /q \"%{IncludeDir.vswhere}\\vswhere.exe\" \"$(OutDir)\"" } filter "configurations:Publish" diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index b17697ad..a8417117 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -28,9 +28,9 @@ of DigiPen Institute of Technology is prohibited. #include "Physics/System/SHPhysicsSystem.h" #include "Physics/SHPhysicsEvents.h" #include "Scene/SHSceneEvents.h" - #include "Assets/SHAssetMacros.h" #include "Tools/Utilities/SHExecUtilities.h" +#include "SHVSUtilities.h" namespace SHADE { @@ -313,11 +313,15 @@ namespace SHADE } // Open it - SHExecUtilties::ExecProcess - ( - L"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe", - L"/Edit " + SHStringUtilities::StrToWstr(CSPROJ_PATH) - ); + try + { + SHVSUtilties::OpenFile(CSPROJ_PATH); + } + catch (std::exception& e) + { + SHLOG_ERROR("{}", e.what()); + SHLOG_ERROR("[SHScriptEngine] Failed to open project csproj file."); + } } /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scripting/SHVSUtilities.cpp b/SHADE_Engine/src/Scripting/SHVSUtilities.cpp index f2fdc0a0..3a53fc79 100644 --- a/SHADE_Engine/src/Scripting/SHVSUtilities.cpp +++ b/SHADE_Engine/src/Scripting/SHVSUtilities.cpp @@ -13,14 +13,51 @@ of DigiPen Institute of Technology is prohibited. #include // Primary Header #include "SHVSUtilities.h" +// Project Headers +#include "Tools/Utilities/SHExecUtilities.h" namespace SHADE { + /*-----------------------------------------------------------------------------------*/ + /* Static Data Members */ + /*-----------------------------------------------------------------------------------*/ + std::filesystem::path SHVSUtilties::devEnvPath; + + /*-----------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------------*/ + void SHVSUtilties::OpenFile(const std::filesystem::path& path) + try + { + if (devEnvPath.empty()) + { + devEnvPath = SHVSUtilties::getDevEnvPath(); + } + SHExecUtilties::ExecProcess(devEnvPath.generic_wstring(), L"/Edit " + path.generic_wstring()); + } + catch (std::exception& e) + { + SHLOG_ERROR("{}", e.what()); + SHLOG_ERROR("[SHVSUtilities] Failed to launch Visual Studio."); + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ std::filesystem::path SHVSUtilties::getDevEnvPath() { - return {}; +#ifdef _PUBLISH + return {}; // Don't do anything if it's a published build +#else + static constexpr int EXCESS_CHARS_COUNT = 2; + + const auto RESULT = SHExecUtilties::ExecBlockingPowerShellCommand(L"./vswhere -version \"[15.0,19.0]\" -requires Microsoft.NetCore.Component.DevelopmentTools -find Common7\\\\IDE\\\\devenv.exe | Select-Object -last 1", true, true); + if (RESULT.StdOutput.size() < EXCESS_CHARS_COUNT) + { + SHLOG_ERROR("[SHVSUtilities] Unable to get path to Visual Studio installation. SHVSUtilities will not work."); + return {}; + } + return RESULT.StdOutput.substr(0, RESULT.StdOutput.size() - EXCESS_CHARS_COUNT); +#endif } } diff --git a/SHADE_Engine/src/Scripting/SHVSUtilities.h b/SHADE_Engine/src/Scripting/SHVSUtilities.h index 52a83e22..5613779b 100644 --- a/SHADE_Engine/src/Scripting/SHVSUtilities.h +++ b/SHADE_Engine/src/Scripting/SHVSUtilities.h @@ -24,7 +24,14 @@ namespace SHADE class SH_API SHVSUtilties final { public: - + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Opens the file at the specified path with a new instance of Visual Studio. + /// + /// Path to the file to open. + static void OpenFile(const std::filesystem::path& path); private: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp index f3f6334d..4a5a963c 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.cpp @@ -15,6 +15,7 @@ of DigiPen Institute of Technology is prohibited. #include "SHExecUtilities.h" // Project Includes #include "SHStringUtilities.h" +#include "SHFileUtilties.h" namespace SHADE { @@ -104,6 +105,26 @@ namespace SHADE ); } + PROCESS_INFORMATION SHExecUtilties::ExecPowerShellCommand(const std::wstring& command) + { + return ExecProcess + ( + L"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", + L"-Command \"& {" + command + L"} \"" + ); + } + + ExecResult SHExecUtilties::ExecBlockingPowerShellCommand(const std::wstring& command, bool output, bool errorOutput) + { + return ExecBlockingProcess + ( + L"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", + L"-Command \"& { cd \"" + SHFileUtilities::GetExecDir().generic_wstring() + L"\";" + command + L"} \"", + output, + errorOutput + ); + } + PROCESS_INFORMATION SHExecUtilties::execProcess(const std::wstring& path, const std::wstring& args, HANDLE outputWritePipe, HANDLE errorOutputWritePipe) { STARTUPINFOW startInfo; @@ -183,7 +204,7 @@ namespace SHADE { std::array buffer{}; DWORD bytesRead = 0; - const auto RESULT = ReadFile(readPipe, buffer.data(), buffer.size(), &bytesRead, nullptr); // Blocking call here? + const auto RESULT = ReadFile(readPipe, buffer.data(), buffer.size(), &bytesRead, nullptr); if (!RESULT || bytesRead <= 0) break; output.insert(output.end(), buffer.data(), buffer.data() + bytesRead); diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h index 9c5f38eb..94c853cd 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h @@ -55,7 +55,7 @@ namespace SHADE /// Arguments to pass to the process. /// If true, stdout will be routed to return. /// If true, outstderr will be routed to return. - /// Return value of the process. + /// Information about the process's execution. /// /// Thrown if failed to start the process. /// @@ -83,7 +83,7 @@ namespace SHADE /// Command to execute. /// If true, stdout will be routed to return. /// If true, outstderr will be routed to return. - /// Return value of the process. + /// Information about the process's execution. /// /// Thrown if failed to start the process. /// @@ -109,11 +109,13 @@ namespace SHADE /// executing. /// /// Command to execute. - /// Return value of the process. + /// If true, stdout will be routed to return. + /// If true, outstderr will be routed to return. + /// Information about the process's execution. /// /// Thrown if failed to start the process. /// - static DWORD ExecBlockingPowerShellCommand(const std::wstring& command); + static ExecResult ExecBlockingPowerShellCommand(const std::wstring& command, bool output, bool errorOutput); private: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.cpp b/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.cpp index 0e75b16a..63e7d26e 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.cpp +++ b/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.cpp @@ -22,9 +22,21 @@ namespace SHADE { void SHFileUtilities::SetWorkDirToExecDir() { - TCHAR currentExecFilePath[MAX_PATH] = { '\0' }; - GetModuleFileName(nullptr, currentExecFilePath, MAX_PATH); - PathRemoveFileSpec(currentExecFilePath); - std::filesystem::current_path(currentExecFilePath); + std::filesystem::current_path(GetExecDir()); + } + + std::filesystem::path SHFileUtilities::GetExecDir() + { + TCHAR currentExecFilePath[MAX_PATH] = { '\0' }; + GetModuleFileName(nullptr, currentExecFilePath, MAX_PATH); + PathRemoveFileSpec(currentExecFilePath); + return std::filesystem::path(currentExecFilePath); + } + + std::filesystem::path SHFileUtilities::GetExecPath() + { + TCHAR currentExecFilePath[MAX_PATH] = { '\0' }; + GetModuleFileName(nullptr, currentExecFilePath, MAX_PATH); + return std::filesystem::path(currentExecFilePath); } } diff --git a/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.h b/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.h index b9ba164b..fdbee34e 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.h +++ b/SHADE_Engine/src/Tools/Utilities/SHFileUtilties.h @@ -15,24 +15,29 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { - /*!************************************************************************************ - - \class SHFileUtilities - - \brief - Static class that contains functions for working with files and directories. - - **************************************************************************************/ + /// + /// Static class that contains functions for working with files and directories. + /// class SH_API SHFileUtilities { public: - /*!********************************************************************************** - - \brief - Sets the application's current working directory to the application executable's - directory. - - ************************************************************************************/ + /*---------------------------------------------------------------------------------*/ + /* Executable Directory Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Sets the application's current working directory to the application executable's + /// directory. + /// static void SetWorkDirToExecDir(); + /// + /// Retrieves the file path to the executable's directory. + /// + /// File path to the executable's directory. + static std::filesystem::path GetExecDir(); + /// + /// Retrieves the file path to the executable. + /// + /// File path to the executable. + static std::filesystem::path GetExecPath(); }; } From fed7f340cd300430bbe7b21d0183472ff07dbe7b Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Fri, 30 Dec 2022 21:57:59 +0800 Subject: [PATCH 22/24] Add Binding Parameters --- SHADE_Engine/src/Input/SHInputManager.h | 40 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/SHADE_Engine/src/Input/SHInputManager.h b/SHADE_Engine/src/Input/SHInputManager.h index 2b9a810f..3f708124 100644 --- a/SHADE_Engine/src/Input/SHInputManager.h +++ b/SHADE_Engine/src/Input/SHInputManager.h @@ -358,7 +358,7 @@ namespace SHADE //How far the user needs to move an analog stick before application //registers the movement - double dead = 0.1; + double dead = 0.2; //Speed in units per second that the axis will move toward target value for digital //For mouse movement / scrolling, serves as multiplier @@ -691,10 +691,32 @@ namespace SHADE return bindings; } - //Add a new binding to the map - static inline void AddBinding(std::string const& newBindingName) noexcept + //Add a new binding to the map with settings + //Binding type is between four different types, + //KB_MB_CONTROLLER Binding is connected to the keyboard, mouse and controller buttons and its analog inputs + //MOUSE_X Binding is connected to horizontal movement of the mouse + //MOUSE_Y Binding is connected to the vertical movement of the mouse + //MOUSE_SCROLL Binding is connected to the scrolling of the mouse wheel + //Inverted is whether positive inputs result in a negative value and vice-versa + //Snap is if inputting in the opposite direction results in the value snapping to 0 before continuing in the direction + //Sensitivity is how fast the value moves with input + //Dead is how much analogue input magnitude on a scale of 0 to 1 is required before being registered + //Gravity is how fast the value moves to neutral without input + static inline void AddBinding(std::string const& newBindingName, + SH_BINDINGTYPE const bindingType = SH_BINDINGTYPE::KB_MB_CONTROLLER, + bool const inverted = false, + bool const snap = false, + double const sensitivity = 1.0, + double const dead = 0.2, + double const gravity = 1.0) noexcept { bindings.insert({ newBindingName, SHLogicalBindingData() }); + bindings[newBindingName].bindingType = bindingType; + bindings[newBindingName].inverted = inverted; + bindings[newBindingName].snap = snap; + bindings[newBindingName].sensitivity = sensitivity; + bindings[newBindingName].dead = dead; + bindings[newBindingName].gravity = gravity; } //Remove a binding and all its associated inputs from the list @@ -741,6 +763,7 @@ namespace SHADE //Gets the gravity of the binding //The rate at which the value moves to neutral if no input in the direction is read //Should be non-negative + //Irrelevant for mouse movement and scrolling static inline double GetBindingGravity(std::string const& bindingName) { return bindings[bindingName].gravity; @@ -749,6 +772,7 @@ namespace SHADE //Sets the gravity of the binding //The rate at which the value moves to neutral if no input in the direction is read //Should be non-negative + //Irrelevant for mouse movement and scrolling static inline void SetBindingGravity(std::string const& bindingName, double const newValue) { bindings[bindingName].gravity = newValue; @@ -756,7 +780,7 @@ namespace SHADE //Get the dead zone of the binding on a scale of 0 to 1, //Any positive or negative analog input with magnitude less than this will be registered as neutral - //irrelvant for digital inputs + //Irrelvant for digital inputs, mouse movement and scrolling static inline double GetBindingDead(std::string const& bindingName) { return bindings[bindingName].dead; @@ -764,7 +788,7 @@ namespace SHADE //Get the dead zone of the binding on a scale of 0 to 1, //Any positive or negative analog input with magnitude less than this will be registered as neutral - //irrelvant for digital inputs + //Irrelvant for digital inputs, mouse movement and scrolling static inline void SetBindingDead(std::string const& bindingName, double const newValue) { bindings[bindingName].dead = newValue; @@ -773,7 +797,7 @@ namespace SHADE //Get the sensitivity of the binding //Serves as a multiplier for mouse movement/scrolling //For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative - //For other analog inputs, serves as a multiplier + //For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1 static inline double GetBindingSensitivity(std::string const& bindingName) { return bindings[bindingName].sensitivity; @@ -782,7 +806,7 @@ namespace SHADE //Set the sensitivity of the binding //Serves as a multiplier for mouse movement/scrolling //For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative - //For other analog inputs, serves as a multiplier + //For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1 static inline void SetBindingSensitivity(std::string const& bindingName, double const newValue) { bindings[bindingName].sensitivity = newValue; @@ -791,6 +815,7 @@ namespace SHADE //Gets the snap of the binding //If no other input on the axis is present and a input is made in the opposite direction of the current value, //the binding's value will jump to neutral 0 before resuming in the input direction + //Irrelevant for mouse movement and scrolling static inline bool GetBindingSnap(std::string const& bindingName) { return bindings[bindingName].snap; @@ -799,6 +824,7 @@ namespace SHADE //Sets the snap of the binding //If no other input on the axis is present and a input is made in the opposite direction of the current value, //the binding's value will jump to neutral 0 before resuming in the input direction + //Irrelevant for mouse movement and scrolling static inline void SetBindingSnap(std::string const& bindingName, bool const newValue) { bindings[bindingName].snap = newValue; From dcf7a65cac2c7fd57faa34b61c88a05134c6d73a Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sat, 31 Dec 2022 00:21:00 +0800 Subject: [PATCH 23/24] Added launching of Visual Studio by double clicking on a script file --- .../AssetBrowser/SHAssetBrowser.cpp | 8 ++ SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 20 ++--- SHADE_Engine/src/Scripting/SHScriptEngine.h | 7 +- SHADE_Engine/src/Scripting/SHVSUtilities.cpp | 74 +++++++++++++++++-- SHADE_Engine/src/Scripting/SHVSUtilities.h | 13 +++- .../src/Tools/Utilities/SHExecUtilities.h | 9 +++ 6 files changed, 108 insertions(+), 23 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 66b3c962..bd39b38e 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -14,6 +14,8 @@ #include "Editor/DragDrop/SHDragDrop.hpp" #include "Editor/EditorWindow/MaterialInspector/SHMaterialInspector.h" #include "Editor/EditorWindow/SHEditorWindowManager.h" +#include "Scripting/SHVSUtilities.h" +#include "Scripting/SHScriptEngine.h" namespace SHADE { @@ -249,6 +251,12 @@ namespace SHADE matInspector->OpenMaterial(asset->id); } break; + case AssetType::SCRIPT: + if(auto scriptEngine = SHSystemManager::GetSystem()) + { + scriptEngine->OpenFile(asset->path); + } + break; case AssetType::MAX_COUNT: break; default:; } diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index a8417117..96f1539d 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -306,22 +306,12 @@ namespace SHADE void SHScriptEngine::OpenSolution() { - // Generate csproj file if it doesn't exist - if (!std::filesystem::exists(CSPROJ_PATH)) - { - GenerateScriptsCsProjFile(CSPROJ_PATH); - } + SHVSUtilties::OpenProject(CSPROJ_PATH); + } - // Open it - try - { - SHVSUtilties::OpenFile(CSPROJ_PATH); - } - catch (std::exception& e) - { - SHLOG_ERROR("{}", e.what()); - SHLOG_ERROR("[SHScriptEngine] Failed to open project csproj file."); - } + void SHScriptEngine::OpenFile(const std::filesystem::path& path) + { + SHVSUtilties::OpenFile(CSPROJ_PATH, path); } /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index d26b360e..9710f5c5 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -218,9 +218,14 @@ namespace SHADE /// File path to the generated file. void GenerateScriptsCsProjFile(const std::filesystem::path& path = CSPROJ_PATH) const; /// - /// Opens the script solution in Visual Studio 2019. + /// Opens the script solution in Visual Studio. /// void OpenSolution(); + /// + /// Opens the file in Visual Studio. + /// + /// + void OpenFile(const std::filesystem::path& path); private: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scripting/SHVSUtilities.cpp b/SHADE_Engine/src/Scripting/SHVSUtilities.cpp index 3a53fc79..17435d6f 100644 --- a/SHADE_Engine/src/Scripting/SHVSUtilities.cpp +++ b/SHADE_Engine/src/Scripting/SHVSUtilities.cpp @@ -22,18 +22,82 @@ namespace SHADE /* Static Data Members */ /*-----------------------------------------------------------------------------------*/ std::filesystem::path SHVSUtilties::devEnvPath; + HANDLE SHVSUtilties::devEnvInst = nullptr; /*-----------------------------------------------------------------------------------*/ /* Usage Functions */ /*-----------------------------------------------------------------------------------*/ - void SHVSUtilties::OpenFile(const std::filesystem::path& path) + void SHVSUtilties::OpenProject(const std::filesystem::path& projPath) try { - if (devEnvPath.empty()) + // Check if there is an instance + bool devEnvActive = false; + if (devEnvInst) { - devEnvPath = SHVSUtilties::getDevEnvPath(); + + DWORD status; + const auto GET_CODE_STATUS = GetExitCodeProcess(devEnvInst, &status); + devEnvActive = GET_CODE_STATUS && status == STILL_ACTIVE; + } + + // Reuse the existing instance if there is one + if (devEnvActive) + { + // No need to reopen one + return; + } + else + { + if (devEnvPath.empty()) + { + devEnvPath = SHVSUtilties::getDevEnvPath(); + } + + auto absProjPath = std::filesystem::canonical(projPath); + auto pi = SHExecUtilties::ExecProcess(devEnvPath.generic_wstring(), L" " + absProjPath.generic_wstring()); + // Cache the process handle + devEnvInst = pi.hProcess; + } + } + catch (std::exception& e) + { + SHLOG_ERROR("{}", e.what()); + SHLOG_ERROR("[SHVSUtilities] Failed to launch Visual Studio."); + } + + void SHVSUtilties::OpenFile(const std::filesystem::path& projPath, const std::filesystem::path& path) + try + { + // Check if there is an instance + bool devEnvActive = false; + if (devEnvInst) + { + + DWORD status; + const auto GET_CODE_STATUS = GetExitCodeProcess(devEnvInst, &status); + devEnvActive = GET_CODE_STATUS && status == STILL_ACTIVE; + } + + auto absPath = std::filesystem::canonical(path); + + // Reuse the existing instance if there is one + if (devEnvActive) + { + // Edit the file only + SHExecUtilties::ExecProcess(devEnvPath.generic_wstring(), L" /Edit " + absPath.generic_wstring()); + } + else + { + if (devEnvPath.empty()) + { + devEnvPath = SHVSUtilties::getDevEnvPath(); + } + + auto absProjPath = std::filesystem::canonical(projPath); + auto pi = SHExecUtilties::ExecProcess(devEnvPath.generic_wstring(), absProjPath.generic_wstring() + L" " + absPath.generic_wstring()); + // Cache the process handle + devEnvInst = pi.hProcess; } - SHExecUtilties::ExecProcess(devEnvPath.generic_wstring(), L"/Edit " + path.generic_wstring()); } catch (std::exception& e) { @@ -51,7 +115,7 @@ namespace SHADE #else static constexpr int EXCESS_CHARS_COUNT = 2; - const auto RESULT = SHExecUtilties::ExecBlockingPowerShellCommand(L"./vswhere -version \"[15.0,19.0]\" -requires Microsoft.NetCore.Component.DevelopmentTools -find Common7\\\\IDE\\\\devenv.exe | Select-Object -last 1", true, true); + const auto RESULT = SHExecUtilties::ExecBlockingPowerShellCommand(L"./vswhere -version \"[15.0,19.0]\" -requires Microsoft.NetCore.Component.DevelopmentTools -find Common7\\\\IDE\\\\devenv.exe | Select-Object -first 1", true, true); if (RESULT.StdOutput.size() < EXCESS_CHARS_COUNT) { SHLOG_ERROR("[SHVSUtilities] Unable to get path to Visual Studio installation. SHVSUtilities will not work."); diff --git a/SHADE_Engine/src/Scripting/SHVSUtilities.h b/SHADE_Engine/src/Scripting/SHVSUtilities.h index 5613779b..8e702dfd 100644 --- a/SHADE_Engine/src/Scripting/SHVSUtilities.h +++ b/SHADE_Engine/src/Scripting/SHVSUtilities.h @@ -28,10 +28,18 @@ namespace SHADE /* Usage Functions */ /*---------------------------------------------------------------------------------*/ /// - /// Opens the file at the specified path with a new instance of Visual Studio. + /// Opens the project at the specified path with a new or existing instance of Visual + /// Studio if it exists. /// + /// Path to the project file to open. + static void OpenProject(const std::filesystem::path& projPath); + /// + /// Opens the file at the specified path with a new or existing instance of Visual + /// Studio if it exists. + /// + /// Path to the project file to open. /// Path to the file to open. - static void OpenFile(const std::filesystem::path& path); + static void OpenFile(const std::filesystem::path& projPath, const std::filesystem::path& path); private: /*---------------------------------------------------------------------------------*/ @@ -43,6 +51,7 @@ namespace SHADE /* Static Data Members */ /*---------------------------------------------------------------------------------*/ static std::filesystem::path devEnvPath; + static HANDLE devEnvInst; /*---------------------------------------------------------------------------------*/ /* Helper Functions */ diff --git a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h index 94c853cd..718fc45b 100644 --- a/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h +++ b/SHADE_Engine/src/Tools/Utilities/SHExecUtilities.h @@ -22,8 +22,17 @@ namespace SHADE /// struct SH_API ExecResult final { + /// + /// Exit code of the process. + /// DWORD Code; + /// + /// Stored text output from the process. + /// std::wstring StdOutput; + /// + /// Stored error text output from the process. + /// std::wstring StdErrOutput; }; From d7754e125dc3684bd97d6b77560569b713058f13 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 1 Jan 2023 12:02:51 +0800 Subject: [PATCH 24/24] Wrote remove resource for render graph (untested) --- SHADE_Engine/src/Events/SHEventDefines.h | 35 +-- .../src/Graphics/Events/SHGraphicsEvents.h | 14 ++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 79 +++++-- .../MiddleEnd/Interface/SHGraphicsSystem.h | 10 +- .../MiddleEnd/Lights/SHLightComponent.cpp | 17 ++ .../MiddleEnd/Lights/SHLightComponent.h | 4 +- .../Graphics/MiddleEnd/Lights/SHLightData.cpp | 6 + .../Graphics/MiddleEnd/Lights/SHLightData.h | 9 + .../Graphics/RenderGraph/SHRenderGraph.cpp | 189 +++++------------ .../src/Graphics/RenderGraph/SHRenderGraph.h | 51 ++++- .../RenderGraph/SHRenderGraphNode.cpp | 200 ++++++++++++++++++ .../Graphics/RenderGraph/SHRenderGraphNode.h | 4 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 144 ++++++++----- .../src/Graphics/RenderGraph/SHSubpass.h | 9 +- 14 files changed, 535 insertions(+), 236 deletions(-) create mode 100644 SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index bdc4c505..8077fcc1 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -5,21 +5,22 @@ typedef uint32_t SHEventIdentifier; typedef uint32_t SHEventHandle; //Add your event identifiers here: -constexpr SHEventIdentifier SH_EXAMPLE_EVENT { 0 }; -constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT { 1 }; -constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT { 2 }; -constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT { 3 }; -constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 }; -constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 }; -constexpr SHEventIdentifier SH_SCENEGRAPH_ADD_CHILD_EVENT { 6 }; -constexpr SHEventIdentifier SH_SCENEGRAPH_REMOVE_CHILD_EVENT { 7 }; -constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 8 }; -constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 }; -constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 }; -constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 }; -constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 }; -constexpr SHEventIdentifier SH_SCENE_INIT_PRE { 13 }; -constexpr SHEventIdentifier SH_SCENE_INIT_POST { 14 }; -constexpr SHEventIdentifier SH_SCENE_EXIT_PRE { 15 }; -constexpr SHEventIdentifier SH_SCENE_EXIT_POST { 16 }; +constexpr SHEventIdentifier SH_EXAMPLE_EVENT { 0 }; +constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT { 1 }; +constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT { 2 }; +constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT { 3 }; +constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 }; +constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 }; +constexpr SHEventIdentifier SH_SCENEGRAPH_ADD_CHILD_EVENT { 6 }; +constexpr SHEventIdentifier SH_SCENEGRAPH_REMOVE_CHILD_EVENT { 7 }; +constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 8 }; +constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 }; +constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 }; +constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 }; +constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 }; +constexpr SHEventIdentifier SH_SCENE_INIT_PRE { 13 }; +constexpr SHEventIdentifier SH_SCENE_INIT_POST { 14 }; +constexpr SHEventIdentifier SH_SCENE_EXIT_PRE { 15 }; +constexpr SHEventIdentifier SH_SCENE_EXIT_POST { 16 }; +constexpr SHEventIdentifier SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT { 17 }; diff --git a/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h b/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h new file mode 100644 index 00000000..ab120a1f --- /dev/null +++ b/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include "ECS_Base/SHECSMacros.h" + +namespace SHADE +{ + struct SHLightEnableShadowEvent + { + //! We need to get the light component and initialize the relevant variables. + EntityID lightEntity; + }; +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6ac941f9..b1256921 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -183,34 +183,32 @@ namespace SHADE /*-----------------------------------------------------------------------*/ // Initialize world render graph renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); - renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource("Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); //worldRenderGraph->AddResource("Tangents", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); - renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); - renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); + renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); renderGraph->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); - renderGraph->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); + renderGraph->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); renderGraph->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); renderGraph->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); renderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second); - /*-----------------------------------------------------------------------*/ /* MAIN NODE */ /*-----------------------------------------------------------------------*/ - auto gBufferNode = renderGraph->AddNode("G-Buffer", + auto gBufferNode = renderGraph->AddNode("G-Buffer", { - "Position", - "Entity ID", + "Position", + "Entity ID", "Light Layer Indices", "Normals", "Albedo", - "Depth Buffer", - "Scene", + "Depth Buffer", "SSAO", "SSAO Blur" - }, + }, {}); // no predecessors /*-----------------------------------------------------------------------*/ @@ -251,23 +249,46 @@ namespace SHADE auto viewSamplerLayout = ssaoStorage->GetViewSamplerLayout(); ssaoPass->ModifyWriteDescImageComputeResource(SHSSAO::DESC_SET_IMAGE_BINDING, { &viewSamplerLayout, 1 }); - ssaoPass->SetRenderer (worldRenderer); + ssaoPass->SetRenderer(worldRenderer); // Add another pass to blur SSAO Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" }); + /*-----------------------------------------------------------------------*/ + /* SHADOW MAP PASS */ + /*-----------------------------------------------------------------------*/ + // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. + // It will initially also not have any subpasses since they will be added for each light that casts shadows. + //auto shadowMapPass = renderGraph->AddNode("Shadow Map Pass", {}, {}); + + + + /*-----------------------------------------------------------------------*/ + /* DEFERRED COMPOSITE NODE */ + /*-----------------------------------------------------------------------*/ + // This pass will facilitate both lighting and shadows in 1 single pass. + auto deferredCompositeNode = renderGraph->AddNode("Deferred Comp Pass", + { + "Position", + "Light Layer Indices", + "Normals", + "Albedo", + "Scene", + "SSAO Blur" + }, + {"G-Buffer"}); + /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - gBufferNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); - + deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); /*-----------------------------------------------------------------------*/ /* DEBUG DRAW PASS INIT */ /*-----------------------------------------------------------------------*/ // Set up Debug Draw Passes // - Depth Tested - auto debugDrawNodeDepth = renderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer"}); + auto debugDrawNodeDepth = renderGraph->AddNode("Debug Draw with Depth", { "Scene", "Depth Buffer" }, {"G-Buffer", "Deferred Comp Pass"}); auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer); debugDrawDepthSubpass->AddColorOutput("Scene"); debugDrawDepthSubpass->AddDepthOutput("Depth Buffer"); @@ -279,7 +300,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SCREEN SPACE PASS */ /*-----------------------------------------------------------------------*/ - auto screenSpaceNode = renderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID" }, {"G-Buffer", "Debug Draw" }); + auto screenSpaceNode = renderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID" }, {"Deferred Comp Pass", "G-Buffer", "Debug Draw" }); auto uiSubpass = screenSpaceNode->AddSubpass("UI", worldViewport, screenRenderer); uiSubpass->AddColorOutput("Scene"); uiSubpass->AddColorOutput("Entity ID"); @@ -410,6 +431,16 @@ namespace SHADE } + void SHGraphicsSystem::InitEvents(void) noexcept + { + std::shared_ptr> thisReceiver + { + std::make_shared>(this, &SHGraphicsSystem::ReceiveLightEnableShadowEvent) + }; + ReceiverPtr receiver = std::dynamic_pointer_cast(thisReceiver); + SHEventManager::SubscribeTo(SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT, receiver); + } + /*---------------------------------------------------------------------------------*/ /* Constructor/Destructors */ /*---------------------------------------------------------------------------------*/ @@ -694,6 +725,18 @@ namespace SHADE renderers.erase(iter); } + SHEventHandle SHGraphicsSystem::ReceiveLightEnableShadowEvent(SHEventPtr event) noexcept + { + // Add the shadow map resource to the graph + + // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. + + // Add a subpass to render to that shadow map + + //renderGraph->GetNode (); + return event->handle; + } + Handle SHGraphicsSystem::AddMaterial(Handle vertShader, Handle fragShader, Handle subpass) { // Retrieve pipeline from pipeline storage or create if unavailable diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 945db2d9..40148e05 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -35,6 +35,7 @@ of DigiPen Institute of Technology is prohibited. #include "Camera/SHCameraDirector.h" #include "Graphics/MiddleEnd/TextRendering/SHFontLibrary.h" #include "Graphics/MiddleEnd/Interface/SHRenderer.h" +#include "Graphics/Events/SHGraphicsEvents.h" namespace SHADE { @@ -102,10 +103,7 @@ namespace SHADE void InitMiddleEnd (void) noexcept; void InitSubsystems (void) noexcept; void InitBuiltInResources (void); - -#ifdef SHEDITOR - void InitEditorRenderGraph (void) noexcept; -#endif + void InitEvents (void) noexcept; public: class SH_API BeginRoutine final : public SHSystemRoutine @@ -176,6 +174,10 @@ namespace SHADE Handle AddRenderer(SHRenderer::PROJECTION_TYPE projectionType); void RemoveRenderer(Handle renderer); + /*-----------------------------------------------------------------------*/ + /* Light functions */ + /*-----------------------------------------------------------------------*/ + SHEventHandle ReceiveLightEnableShadowEvent (SHEventPtr event) noexcept; /*-----------------------------------------------------------------------------*/ /* Material Functions */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 2ea6bc8b..362b0e8f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -1,5 +1,7 @@ #include "SHpch.h" #include "SHLightComponent.h" +#include "Graphics/Events/SHGraphicsEvents.h" +#include "Events/SHEventManager.hpp" namespace SHADE { @@ -104,6 +106,21 @@ namespace SHADE //MakeDirty(); } + void SHLightComponent::SetEnableShadow(bool flag) noexcept + { + lightData.castShadows = flag; + + // If the flag is true + if (flag && lightData.shadowMapIndex == SHLightData::INVALID_SHADOW_MAP_INDEX) + { + // Create new event and broadcast it + SHLightEnableShadowEvent newEvent; + newEvent.lightEntity = GetEID(); + + SHEventManager::BroadcastEvent(newEvent, SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT); + } + } + SHLightData const& SHLightComponent::GetLightData(void) const noexcept { return lightData; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 6b35559c..1d636595 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -25,7 +25,6 @@ namespace SHADE ////! If the light's data is already in the buffers, this will be set to true. //bool bound; - public: /*-----------------------------------------------------------------------*/ /* LIFECYCLE FUNCTIONS */ @@ -49,6 +48,7 @@ namespace SHADE //void Unbind (void) noexcept; //void SetBound (uint32_t inIndexInBuffer) noexcept; void SetStrength (float value) noexcept; // serialized + void SetEnableShadow (bool flag) noexcept; SHLightData const& GetLightData (void) const noexcept; @@ -59,7 +59,7 @@ namespace SHADE uint32_t const& GetCullingMask (void) const noexcept; // serialized //bool IsDirty (void) const noexcept; //bool GetBound (void) const noexcept; - uint32_t GetIndexInBuffer (void) const noexcept; + //uint32_t GetIndexInBuffer (void) const noexcept; float GetStrength (void) const noexcept; RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp index 8e8f0783..f51fdfa7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp @@ -16,6 +16,12 @@ namespace SHADE // Diffuse color set to 1 color = SHVec4::One; + + // light will default not cast shadows + castShadows = false; + + // shadow map index is invalid. + shadowMapIndex = INVALID_SHADOW_MAP_INDEX; } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h index e9a02c1a..4d62700d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h @@ -26,6 +26,8 @@ namespace SHADE /***************************************************************************/ struct SHLightData { + static constexpr uint32_t INVALID_SHADOW_MAP_INDEX = std::numeric_limits::max(); + //! position of the light SHVec3 position; @@ -46,6 +48,13 @@ namespace SHADE //! Strength of the light float strength; + //! Whether or not the light will cast a shadow. More technically, whether or + //! not the light will result in the addition of a depth map into the render graph + //! to be used for shadow mapping calculations. + bool castShadows; + + //! Index of the shadow map when it gets placed in the descriptor array of textures (that are all shadow maps). + uint32_t shadowMapIndex; void Reset (void) noexcept; //! TODO: diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 67cc9112..74371a64 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -68,6 +68,56 @@ namespace SHADE renderGraphStorage->graphResources->try_emplace(resourceName, resource); } + + void SHRenderGraph::RemoveResource(std::string resourceName) noexcept + { + // 1. Check if nodes are using said attachment and remove if they are + // - Check subpasses while at it and remove as well if used as attachment + // 2. Regenerate graph + // - Delete all vulkan objects first as well and clear the necessary containers + + if (!renderGraphStorage->graphResources->contains(resourceName)) + return; + + renderGraphStorage->logicalDevice->WaitIdle(); + + uint64_t handleID = renderGraphStorage->graphResources->at (resourceName).GetId().Raw; + + // Record nodes that will be affected + std::vector affectedNodes{}; + + // Detach resource from all nodes if applicable + for (uint32_t i = 0; i < nodes.size(); ++i) + { + if (nodes[i]->DetachResource(resourceName, handleID)) + affectedNodes.emplace_back(i); + } + + // Up to this point the nodes and subpasses should have no trace of the deleted resource. Attachment + // descriptions and subpass indices should also have been reconfigured at this point. However, this + // means that the subpass descriptions and subpass dependencies need to be reconfigured. + + // configure subpass dependencies and descriptions. + for (auto& affectedNode : affectedNodes) + nodes[affectedNode]->ConfigureSubpasses(); + + for (auto& affectedNode : affectedNodes) + nodes[affectedNode]->CreateRenderpass(); + + for (auto& affectedNode : affectedNodes) + nodes[affectedNode]->CreateFramebuffer(); + /* + * IMPORTANT NOTES + * + * This remove resource function would be more complete if it accounted for renderpass compatibility by + * recreating the graphics pipelines stored in render graph nodes. However due to time constraints, this is left out. As such, + * pipelines that are recreated with a certain renderpass and subpass will assumed to be compatible when used in different subpasses. + * + * This function also recreates renderpasses and framebuffers so it does not account for removing of resources that are used in nodes whose + * renderpasses and framebuffers are used externally in systems like Editor with ImGui. + */ + } + void SHRenderGraph::LinkNonOwningResource(Handle resourceOrigin, std::string resourceName) noexcept { // resource to link @@ -236,140 +286,12 @@ namespace SHADE */ /***************************************************************************/ - void SHRenderGraph::ConfigureSubpasses(void) noexcept + void SHRenderGraph::ConfigureAllSubpasses(void) noexcept { // For all nodes for (auto& node : nodes) { - // Create subpass description and dependencies based on number of subpasses - node->spDescs.resize(node->subpasses.size()); - node->spDeps.resize(node->subpasses.size()); - - // Now we want to loop through all attachments in all subpasses in the node and query - // the resources being used. For each resource we want to query the type and record it - // in bit fields (1 bit for each subpass). - uint32_t colorRead = 0, colorWrite = 0, depthRead = 0, depthWrite = 0, inputDependencies = 0; - - uint32_t i = 0; - - // For all subpasses (see above description about bit field for this). - for (auto& subpass : node->subpasses) - { - // Configure subpass description - auto& desc = node->spDescs[i]; - desc.pColorAttachments = subpass->colorReferences.data(); - desc.colorAttachmentCount = static_cast(subpass->colorReferences.size()); - desc.pInputAttachments = subpass->inputReferences.data(); - desc.inputAttachmentCount = static_cast(subpass->inputReferences.size()); - desc.pDepthStencilAttachment = subpass->depthReferences.data(); - desc.pipelineBindPoint = vk::PipelineBindPoint::eGraphics; // TODO: Just graphics for now. See if its possible to allow user defined params. - - // Get reference to subpass description - auto& dep = node->spDeps[i]; - - // Configure subpass index for dependencies - dep.srcSubpass = (i == 0) ? VK_SUBPASS_EXTERNAL : i - 1; - dep.dstSubpass = i; - - // First we want to see if the subpass has color, depth or input attachments and set bit field accordingly - if (subpass->colorReferences.size()) - { - colorRead |= (1 << i); - colorWrite |= (1 << i); - } - - // Same thing for depth - if (subpass->depthReferences.size()) - { - depthRead |= (1 << i); - depthWrite |= (1 << i); - } - if (subpass->inputReferences.size()) - inputDependencies |= (1 << i); - - // Input attachments can be any type, so we need to check what type it is - for (auto& inputAtt : subpass->inputReferences) - { - auto resource = node->attResources[inputAtt.attachment]; - if (resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT)) - { - if (resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR) || - resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) - colorRead |= (1 << i); - else if (resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL)) - depthRead |= (1 << i); - } - else - { - SHLOG_ERROR("While configuring subpass, an input reference was detected but the resource to be used is not marked as SH_ATT_DESC_TYPE_FLAGS::INPUT. "); - } - } - - ++i; - } - - // Loop through all subpasses again but this time we use the bit field to initialize - // the dependencies. - for (i = 0; i < node->subpasses.size(); ++i) - { - vk::PipelineStageFlags srcStage; - vk::PipelineStageFlags dstStage; - vk::AccessFlags srcAccess; - vk::AccessFlags dstAccess; - auto& dep = node->spDeps[i]; - - if (colorRead & (1 << i)) - { - srcStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; - dstStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; - srcAccess |= vk::AccessFlagBits::eColorAttachmentWrite; - dstAccess |= vk::AccessFlagBits::eColorAttachmentRead; - } - if (colorWrite & (1 << i)) - { - srcStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; - dstStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; - srcAccess |= vk::AccessFlagBits::eColorAttachmentWrite; - dstAccess |= vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentRead; - } - if (depthRead & (1 << i)) - { - srcStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests; - dstStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests; - srcAccess |= vk::AccessFlagBits::eDepthStencilAttachmentWrite; - dstAccess |= vk::AccessFlagBits::eDepthStencilAttachmentRead; - } - if (depthWrite & (1 << i)) - { - srcStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests; - dstStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests; - srcAccess |= vk::AccessFlagBits::eDepthStencilAttachmentWrite; - dstAccess |= vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite; - } - if (inputDependencies & (1 << i)) - { - dstStage |= vk::PipelineStageFlagBits::eFragmentShader; - dstAccess |= vk::AccessFlagBits::eInputAttachmentRead; - } - - //// If subpass of first renderpass, stage flag should be bottom of pipe - //if (&node == &nodes.front() && i == 0) - // srcStage = vk::PipelineStageFlagBits::eBottomOfPipe; - - //// If subpass of last renderpass, stage flag should be bottom of pipe - //if (&node == &nodes.back() && i == node->subpasses.size() - 1) - // dstStage = vk::PipelineStageFlagBits::eTopOfPipe; - - dep.srcStageMask = srcStage; - dep.dstStageMask = dstStage; - dep.srcAccessMask = srcAccess; - dep.dstAccessMask = dstAccess; - - dep.srcStageMask = srcStage; - - // initialize input descriptors - node->subpasses[i]->CreateInputDescriptors(); - } + node->ConfigureSubpasses(); } } @@ -604,12 +526,17 @@ namespace SHADE { CheckForNodeComputes(); ConfigureAttachmentDescriptions(); - ConfigureSubpasses(); + ConfigureAllSubpasses(); ConfigureRenderpasses(); ConfigureFramebuffers(); ConfigureSubSystems(); } + void SHRenderGraph::Regenerate(void) noexcept + { + + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 948fd9f7..c7fe221b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -51,7 +51,7 @@ namespace SHADE /* PRIVATE MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ void ConfigureAttachmentDescriptions (void) noexcept; - void ConfigureSubpasses (void) noexcept; + void ConfigureAllSubpasses (void) noexcept; void ConfigureRenderpasses (void) noexcept; void ConfigureSubSystems (void) noexcept; void ConfigureFramebuffers (void) noexcept; @@ -89,13 +89,52 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (std::string graphName, Handle logicalDevice, Handle swapchain, SHResourceHub* resourceHub, std::vector>& cmdPools) noexcept; - void AddResource(std::string resourceName, std::initializer_list typeFlags, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageUsageFlagBits usageFlags = {}, vk::ImageCreateFlagBits createFlags = {}); - void LinkNonOwningResource (Handle resourceOrigin, std::string resourceName) noexcept; - Handle AddNode (std::string nodeName, std::initializer_list resourceInstruction, std::initializer_list predecessorNodes) noexcept; - void AddRenderToSwapchainNode (std::string toSwapchainResource, std::string swapchainResource, std::initializer_list predecessorNodes, std::pair, Handle> shaderModules) noexcept; + void Init + ( + std::string graphName, + Handle logicalDevice, + Handle swapchain, SHResourceHub* resourceHub, + std::vector>& cmdPools + ) noexcept; + + void AddResource + ( + std::string resourceName, + std::initializer_list typeFlags, + uint32_t w = static_cast(-1), + uint32_t h = static_cast(-1), + vk::Format format = vk::Format::eB8G8R8A8Unorm, + uint8_t levels = 1, + vk::ImageUsageFlagBits usageFlags = {}, + vk::ImageCreateFlagBits createFlags = {} + ); + + void RemoveResource (std::string resourceName) noexcept; + + void LinkNonOwningResource + ( + Handle resourceOrigin, + std::string resourceName + ) noexcept; + + Handle AddNode + ( + std::string nodeName, + std::initializer_list resourceInstruction, + std::initializer_list predecessorNodes + ) noexcept; + + void AddRenderToSwapchainNode + ( + std::string toSwapchainResource, + std::string swapchainResource, + std::initializer_list predecessorNodes, + std::pair, + Handle> shaderModules + ) noexcept; void Generate (void) noexcept; + void Regenerate (void) noexcept; void CheckForNodeComputes (void) noexcept; void Execute (uint32_t frameIndex, Handle descPool) noexcept; void Begin (uint32_t frameIndex) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index b8185176..3c412645 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -26,6 +26,12 @@ namespace SHADE /***************************************************************************/ void SHRenderGraphNode::CreateRenderpass(void) noexcept { + if (renderpass) + { + if (renderpass) + renderpass.Free(); + } + renderpass = graphStorage->logicalDevice->CreateRenderpass(attachmentDescriptions, spDescs, spDeps); SET_VK_OBJ_NAME(graphStorage->logicalDevice, vk::ObjectType::eRenderPass, renderpass->GetVkRenderpass(), "[RenderPass] " + name); } @@ -40,6 +46,15 @@ namespace SHADE /***************************************************************************/ void SHRenderGraphNode::CreateFramebuffer(void) noexcept { + if (!framebuffers.empty()) + { + for (auto fbo : framebuffers) + { + if (fbo) + fbo.Free(); + } + } + for (uint32_t i = 0; i < framebuffers.size(); ++i) { std::vector> imageViews(attResources.size()); @@ -100,6 +115,139 @@ namespace SHADE } } + void SHRenderGraphNode::ConfigureSubpasses(void) noexcept + { + // Create subpass description and dependencies based on number of subpasses + spDescs.resize(subpasses.size()); + spDeps.resize(subpasses.size()); + + // Now we want to loop through all attachments in all subpasses in the node and query + // the resources being used. For each resource we want to query the type and record it + // in bit fields (1 bit for each subpass). + uint32_t colorRead = 0, colorWrite = 0, depthRead = 0, depthWrite = 0, inputDependencies = 0; + + uint32_t i = 0; + + // For all subpasses (see above description about bit field for this). + for (auto& subpass : subpasses) + { + // Configure subpass description + auto& desc = spDescs[i]; + desc.pColorAttachments = subpass->colorReferences.data(); + desc.colorAttachmentCount = static_cast(subpass->colorReferences.size()); + desc.pInputAttachments = subpass->inputReferences.data(); + desc.inputAttachmentCount = static_cast(subpass->inputReferences.size()); + desc.pDepthStencilAttachment = subpass->depthReferences.data(); + desc.pipelineBindPoint = vk::PipelineBindPoint::eGraphics; // TODO: Just graphics for now. See if its possible to allow user defined params. + + // Get reference to subpass description + auto& dep = spDeps[i]; + + // Configure subpass index for dependencies + dep.srcSubpass = (i == 0) ? VK_SUBPASS_EXTERNAL : i - 1; + dep.dstSubpass = i; + + // First we want to see if the subpass has color, depth or input attachments and set bit field accordingly + if (subpass->colorReferences.size()) + { + colorRead |= (1 << i); + colorWrite |= (1 << i); + } + + // Same thing for depth + if (subpass->depthReferences.size()) + { + depthRead |= (1 << i); + depthWrite |= (1 << i); + } + if (subpass->inputReferences.size()) + inputDependencies |= (1 << i); + + // Input attachments can be any type, so we need to check what type it is + for (auto& inputAtt : subpass->inputReferences) + { + auto resource = attResources[inputAtt.attachment]; + if (resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT)) + { + if (resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR) || + resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) + colorRead |= (1 << i); + else if (resource->resourceTypeFlags & static_cast(SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL)) + depthRead |= (1 << i); + } + else + { + SHLOG_ERROR("While configuring subpass, an input reference was detected but the resource to be used is not marked as SH_ATT_DESC_TYPE_FLAGS::INPUT. "); + } + } + + ++i; + } + + // Loop through all subpasses again but this time we use the bit field to initialize + // the dependencies. + for (i = 0; i < subpasses.size(); ++i) + { + vk::PipelineStageFlags srcStage; + vk::PipelineStageFlags dstStage; + vk::AccessFlags srcAccess; + vk::AccessFlags dstAccess; + auto& dep = spDeps[i]; + + if (colorRead & (1 << i)) + { + srcStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; + dstStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; + srcAccess |= vk::AccessFlagBits::eColorAttachmentWrite; + dstAccess |= vk::AccessFlagBits::eColorAttachmentRead; + } + if (colorWrite & (1 << i)) + { + srcStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; + dstStage |= vk::PipelineStageFlagBits::eColorAttachmentOutput; + srcAccess |= vk::AccessFlagBits::eColorAttachmentWrite; + dstAccess |= vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentRead; + } + if (depthRead & (1 << i)) + { + srcStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests; + dstStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests; + srcAccess |= vk::AccessFlagBits::eDepthStencilAttachmentWrite; + dstAccess |= vk::AccessFlagBits::eDepthStencilAttachmentRead; + } + if (depthWrite & (1 << i)) + { + srcStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests; + dstStage |= vk::PipelineStageFlagBits::eEarlyFragmentTests | vk::PipelineStageFlagBits::eLateFragmentTests; + srcAccess |= vk::AccessFlagBits::eDepthStencilAttachmentWrite; + dstAccess |= vk::AccessFlagBits::eDepthStencilAttachmentRead | vk::AccessFlagBits::eDepthStencilAttachmentWrite; + } + if (inputDependencies & (1 << i)) + { + dstStage |= vk::PipelineStageFlagBits::eFragmentShader; + dstAccess |= vk::AccessFlagBits::eInputAttachmentRead; + } + + //// If subpass of first renderpass, stage flag should be bottom of pipe + //if (&node == &nodes.front() && i == 0) + // srcStage = vk::PipelineStageFlagBits::eBottomOfPipe; + + //// If subpass of last renderpass, stage flag should be bottom of pipe + //if (&node == &nodes.back() && i == subpasses.size() - 1) + // dstStage = vk::PipelineStageFlagBits::eTopOfPipe; + + dep.srcStageMask = srcStage; + dep.dstStageMask = dstStage; + dep.srcAccessMask = srcAccess; + dep.dstAccessMask = dstAccess; + + dep.srcStageMask = srcStage; + + // initialize input descriptors + subpasses[i]->CreateInputDescriptors(); + } + } + /***************************************************************************/ /*! @@ -335,6 +483,58 @@ namespace SHADE } } + /***************************************************************************/ + /*! + + \brief + For detaching attachments from the node. The node would need to be + rebuilt but it won't be done in this function. This function just removes + any footprint of the resource in the class. + + \param resourceHandleID + The handle ID of the resource. + + */ + /***************************************************************************/ + bool SHRenderGraphNode::DetachResource(std::string const& resourceName, uint64_t resourceHandleID) noexcept + { + if (resourceAttachmentMapping->contains(resourceHandleID)) + { + // Get attachment index in the node's attachment container + auto index = resourceAttachmentMapping->at(resourceHandleID); + + // remove attachment from the list of attachments + attResources.erase (attResources.begin() + index); + + // remove attachment reference + attachmentDescriptions.erase (attachmentDescriptions.begin() + index); + + // Remove footprint of attachment from all subpasses as well + for (auto it = subpasses.begin(); it != subpasses.end(); ++it) + { + // attempt to detach resource from subpass + (*it)->DetachResource(resourceName, index); + + // If the subpass ends up having no attachments after, erase it from the node + if ((*it)->HasNoAttachments()) + { + // erase from indexing + subpassIndexing.erase((*it)->GetName()); + + // erase from container of subpasses. + it = subpasses.erase(it); + } + } + + // give existing subpasses new indices + for (uint32_t i = 0; i < subpasses.size(); ++i) + subpasses[i]->SetIndex(i); + + return true; + } + return false; + } + void SHRenderGraphNode::Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { uint32_t framebufferIndex = (framebuffers.size() > 1) ? frameIndex : 0; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index ebaf48e2..a581d21c 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -55,7 +55,7 @@ namespace SHADE //! Vector of subpasses std::vector> subpasses; - //! Descriptions to pass to renderpass for renderpass creation. We want to keep this here because + //! Descriptions to pass to renderpass for renderpass creation. std::vector spDescs; //! Subpass dependencies for renderpass creation @@ -92,6 +92,7 @@ namespace SHADE void CreateRenderpass(void) noexcept; void CreateFramebuffer(void) noexcept; void HandleResize (void) noexcept; + void ConfigureSubpasses (void) noexcept; public: /*-----------------------------------------------------------------------*/ @@ -107,6 +108,7 @@ namespace SHADE Handle AddSubpass(std::string subpassName, Handle viewport, Handle renderer) noexcept; Handle AddNodeCompute(std::string nodeName, Handle computeShaderModule, std::initializer_list resources, std::unordered_set&& dynamicBufferBindings = {}, float numWorkGroupScale = 1.0f) noexcept; void AddDummySubpassIfNeeded (void) noexcept; + bool DetachResource (std::string const& resourceName, uint64_t resourceHandleID) noexcept; // TODO: RemoveSubpass() void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 88d375ce..3d2b1699 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -68,7 +68,6 @@ namespace SHADE , depthReferences{ std::move(rhs.depthReferences) } , inputReferences{ std::move(rhs.inputReferences) } , resourceAttachmentMapping{ rhs.resourceAttachmentMapping } - , descriptorSetLayout{ rhs.descriptorSetLayout } , exteriorDrawCalls{ std::move(rhs.exteriorDrawCalls) } , graphStorage{ rhs.graphStorage } , inputNames{ std::move(rhs.inputNames) } @@ -105,7 +104,6 @@ namespace SHADE depthReferences = std::move(rhs.depthReferences); inputReferences = std::move(rhs.inputReferences); resourceAttachmentMapping = std::move(rhs.resourceAttachmentMapping); - descriptorSetLayout = rhs.descriptorSetLayout; exteriorDrawCalls = std::move(rhs.exteriorDrawCalls); graphStorage = rhs.graphStorage; inputNames = std::move(rhs.inputNames); @@ -253,6 +251,64 @@ namespace SHADE } } + /***************************************************************************/ + /*! + + \brief + Removes all footprints of a resource in the subpass. + + \param resourceName + Name of resource. + + \param attachmentIndex + index of attachment. + + */ + /***************************************************************************/ + void SHSubpass::DetachResource(std::string const& resourceName, uint32_t attachmentIndex) noexcept + { + for (uint32_t i = 0; i < colorReferences.size(); ++i) + { + if (colorReferences[i].attachment == attachmentIndex) + { + colorReferences.erase (colorReferences.begin() + i); + break; + } + } + + for (uint32_t i = 0; i < depthReferences.size(); ++i) + { + if (depthReferences[i].attachment == attachmentIndex) + { + depthReferences.erase(depthReferences.begin() + i); + break; + } + } + + for (uint32_t i = 0; i < inputReferences.size(); ++i) + { + if (inputReferences[i].attachment == attachmentIndex) + { + inputReferences.erase(inputReferences.begin() + i); + break; + } + } + + for (uint32_t i = 0; i < inputNames.size(); ++i) + { + if (inputNames[i] == resourceName) + { + inputNames.erase(inputNames.begin() + i); + break; + } + } + } + + bool SHSubpass::HasNoAttachments(void) const noexcept + { + return colorReferences.empty() && depthReferences.empty() && inputReferences.empty(); + } + void SHSubpass::AddExteriorDrawCalls(ExteriorDrawCallFunction const& newDrawCall) noexcept { exteriorDrawCalls.push_back(newDrawCall); @@ -269,6 +325,21 @@ namespace SHADE if (inputNames.empty()) return; + for (auto& set : inputImageDescriptorSets) + { + if (set) + set.Free(); + } + + if (inputDescriptorLayout) + inputDescriptorLayout.Free(); + + for (auto& sampler : inputSamplers) + { + if (sampler) + sampler.Free(); + } + inputImageDescriptorSets.resize(SHGraphicsConstants::NUM_FRAME_BUFFERS); std::vector bindings{}; @@ -369,58 +440,23 @@ namespace SHADE } } - //void SHSubpass::InitComputeBarriers(void) noexcept - //{ - // std::unordered_set handleBarriers{}; - - // // we will have swapchainNumImages vectors of vector of barriers - // subpassComputeBarriers.resize(graphStorage->swapchain->GetNumImages()); - - // for (auto sbCompute : subpassComputes) - // { - // // for every resource the subpass compute is using - // for (auto resource : sbCompute->resources) - // { - // // Get the resource handle - // uint64_t resourceRaw = resource.GetId().Raw; - - // // if the barrier is not registered - // if (!handleBarriers.contains(resourceRaw)) - // { - // // If the resource is a swapchain image - // bool isSwapchainImage = (resource->resourceTypeFlags & static_cast(SH_ATT_DESC_TYPE_FLAGS::COLOR_PRESENT)); - // for (uint32_t i = 0; i < graphStorage->swapchain->GetNumImages(); ++i) - // { - // // if swapchain image, we want the index of the swapchain image, if not take base image - // uint32_t imageIndex = isSwapchainImage ? i : 0; - - // // Prepare image barrier - // vk::ImageMemoryBarrier imageBarrier - // { - // .oldLayout = colorReferences[resourceAttachmentMapping->at(resource.GetId().Raw)].layout, - // .newLayout = vk::ImageLayout::eGeneral, - // .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - // .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - // .image = resource->GetImage(imageIndex)->GetVkImage(), - // .subresourceRange = - // { - // .aspectMask = resource->imageAspectFlags, - // .levelCount = resource->GetMipLevels(), - // .baseArrayLayer = 0, - // .layerCount = 1 - // } - // }; - - // // push the barrier - // subpassComputeBarriers[i].push_back(imageBarrier); - // } - - // // Image transition registered - // handleBarriers.emplace(resourceRaw); - // } - // } - // } - //} + /***************************************************************************/ + /*! + + \brief + This function is mainly used for the purposes of giving a subpass a new + index in the case another subpass in the node gets deleted, and subpasses + need to be re-indexed. + + \param index + New index of the subpass. + + */ + /***************************************************************************/ + void SHSubpass::SetIndex(uint32_t index) noexcept + { + subpassIndex = index; + } /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 66d41ffd..6c582aa6 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -50,9 +50,6 @@ namespace SHADE //! Handle superBatch; - //! Descriptor set layout to hold attachments - Handle descriptorSetLayout; - //! Color attachments std::vector colorReferences; @@ -122,6 +119,8 @@ namespace SHADE void Execute(Handle commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; void BindInputDescriptorSets (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) const noexcept; + void DetachResource (std::string const& resourceName, uint32_t attachmentIndex) noexcept; + bool HasNoAttachments (void) const noexcept; void Init(SHResourceHub& resourceManager) noexcept; @@ -132,6 +131,10 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* GETTERS AND SETTERS */ /*-----------------------------------------------------------------------*/ + private: + void SetIndex (uint32_t index) noexcept; + + public: Handle const& GetParentNode(void) const noexcept; SHSubPassIndex GetIndex() const noexcept; Handle GetSuperBatch(void) const noexcept;