From 9ef947300451091ab2385df78fd02823a393acd5 Mon Sep 17 00:00:00 2001 From: Panos Karabelas Date: Sun, 24 Nov 2024 22:47:06 +0000 Subject: [PATCH] [resource] introduced resource state enum which will be the bedrock for multi-threaded loading (also removed some unused headers from header files) --- editor/EditorWindow.cpp | 1 + editor/ImGui/ImGuiExtension.h | 2 ++ runtime/RHI/RHI_Texture.cpp | 6 +++--- runtime/Rendering/Material.cpp | 6 +++--- runtime/Rendering/Mesh.h | 1 + runtime/Resource/IResource.h | 16 +++++++++++----- runtime/Resource/ResourceCache.cpp | 5 +++-- runtime/Resource/ResourceCache.h | 7 +++---- runtime/World/Components/Terrain.cpp | 1 + 9 files changed, 28 insertions(+), 17 deletions(-) diff --git a/editor/EditorWindow.cpp b/editor/EditorWindow.cpp index 9a188b783..ea0b22d67 100644 --- a/editor/EditorWindow.cpp +++ b/editor/EditorWindow.cpp @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Widgets/Viewport.h" #include "Input/Input.h" #include "Game/Game.h" +#include "Core/ProgressTracker.h" //=============================== //= NAMESPACES ===== diff --git a/editor/ImGui/ImGuiExtension.h b/editor/ImGui/ImGuiExtension.h index f1b7e5167..c8697b530 100644 --- a/editor/ImGui/ImGuiExtension.h +++ b/editor/ImGui/ImGuiExtension.h @@ -24,6 +24,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //= INCLUDES ====================== #include #include +#include "Definitions.h" +#include "Logging/Log.h" #include "Window.h" #include "RHI/RHI_Texture.h" #include "Rendering/Renderer.h" diff --git a/runtime/RHI/RHI_Texture.cpp b/runtime/RHI/RHI_Texture.cpp index 8eb719aa8..55c4a7924 100644 --- a/runtime/RHI/RHI_Texture.cpp +++ b/runtime/RHI/RHI_Texture.cpp @@ -221,7 +221,7 @@ namespace Spartan if (!(flags & RHI_Texture_DontOptimize)) { RHI_Texture::RHI_CreateResource(); - m_is_gpu_ready = true; + m_resource_state = ResourceState::Ready; } if (!compressonator::registered) @@ -523,7 +523,7 @@ namespace Spartan void RHI_Texture::PrepareForGpu() { - SP_ASSERT_MSG(!m_is_gpu_ready, "The texture is already optimized"); + SP_ASSERT_MSG(!IsGpuReady(), "The texture is already optimized"); SP_ASSERT(m_slices.size() > 0); SP_ASSERT(m_slices[0].mips.size() > 0); @@ -591,7 +591,7 @@ namespace Spartan } ComputeMemoryUsage(); - m_is_gpu_ready = true; + m_resource_state = ResourceState::Ready; } void RHI_Texture::SaveAsImage(const string& file_path) diff --git a/runtime/Rendering/Material.cpp b/runtime/Rendering/Material.cpp index 319f1014e..10f544d66 100644 --- a/runtime/Rendering/Material.cpp +++ b/runtime/Rendering/Material.cpp @@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "../Resource/ResourceCache.h" #include "../RHI/RHI_Texture.h" #include "../World/World.h" +#include "../Core/ProgressTracker.h" SP_WARNINGS_OFF #include "../IO/pugixml.hpp" SP_WARNINGS_ON @@ -322,7 +323,7 @@ namespace Spartan void Material::Optimize(const bool is_gltf) { - SP_ASSERT_MSG(!m_is_gpu_ready, "The material is already optimized"); + SP_ASSERT_MSG(!IsGpuReady(), "The material is already optimized"); RHI_Texture* texture_color = GetTexture(MaterialTextureType::Color); RHI_Texture* texture_alpha_mask = GetTexture(MaterialTextureType::AlphaMask); @@ -451,8 +452,7 @@ namespace Spartan } SetProperty(MaterialProperty::Optimized, is_optimized ? 1.0f : 0.0f); - m_is_gpu_ready = true; - + m_resource_state = ResourceState::Ready; } uint32_t Material::GetUsedSlotCount() const diff --git a/runtime/Rendering/Mesh.h b/runtime/Rendering/Mesh.h index 04302ff3b..ba42cdaae 100644 --- a/runtime/Rendering/Mesh.h +++ b/runtime/Rendering/Mesh.h @@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //= INCLUDES ===================== #include +#include #include "Material.h" #include "../Resource/IResource.h" #include "../Math/BoundingBox.h" diff --git a/runtime/Resource/IResource.h b/runtime/Resource/IResource.h index 5bf5701cd..b6756a59a 100644 --- a/runtime/Resource/IResource.h +++ b/runtime/Resource/IResource.h @@ -25,7 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include "../Core/FileSystem.h" #include "../Core/SpartanObject.h" -#include "../Logging/Log.h" //================================ namespace Spartan @@ -44,6 +43,13 @@ namespace Spartan Max, }; + enum class ResourceState + { + Processed, + Ready, + Max + }; + class IResource : public SpartanObject { public: @@ -95,7 +101,7 @@ namespace Spartan void SetFlags(const uint32_t flags) { m_flags = flags; } // ready to use - bool IsGpuReady() const { return m_is_gpu_ready; } + bool IsGpuReady() const { return m_resource_state == ResourceState::Ready; } // io virtual bool SaveToFile(const std::string& file_path) { return true; } @@ -106,9 +112,9 @@ namespace Spartan static constexpr ResourceType TypeToEnum(); protected: - ResourceType m_resource_type = ResourceType::Max; - std::atomic m_is_gpu_ready = false; - uint32_t m_flags = 0; + ResourceType m_resource_type = ResourceType::Max; + std::atomic m_resource_state = ResourceState::Max; + uint32_t m_flags = 0; private: std::string m_resource_directory; diff --git a/runtime/Resource/ResourceCache.cpp b/runtime/Resource/ResourceCache.cpp index 7838e9b7c..1321a20cd 100644 --- a/runtime/Resource/ResourceCache.cpp +++ b/runtime/Resource/ResourceCache.cpp @@ -19,7 +19,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -//= INCLUDES ==================== +//= INCLUDES ======================= #include "pch.h" #include "ResourceCache.h" #include "../World/World.h" @@ -27,7 +27,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "../RHI/RHI_Texture.h" #include "../Audio/AudioClip.h" #include "../Rendering/Mesh.h" -//=============================== +#include "../Core/ProgressTracker.h" +//================================== //= NAMESPACES ================ using namespace std; diff --git a/runtime/Resource/ResourceCache.h b/runtime/Resource/ResourceCache.h index fe21a2f5b..08370b321 100644 --- a/runtime/Resource/ResourceCache.h +++ b/runtime/Resource/ResourceCache.h @@ -21,11 +21,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #pragma once -//= INCLUDES =============== -#include +//= INCLUDES ============== #include "IResource.h" -#include "ProgressTracker.h" -//========================== +#include "../Logging/Log.h" +//========================= namespace Spartan { diff --git a/runtime/World/Components/Terrain.cpp b/runtime/World/Components/Terrain.cpp index eb6a35974..8344c3eef 100644 --- a/runtime/World/Components/Terrain.cpp +++ b/runtime/World/Components/Terrain.cpp @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "../../Resource/ResourceCache.h" #include "../../Rendering/Mesh.h" #include "../../Core/ThreadPool.h" +#include "../../Core/ProgressTracker.h" //======================================= //= NAMESPACES ===============