Skip to content

Commit

Permalink
[resource] introduced resource state enum which will be the bedrock f…
Browse files Browse the repository at this point in the history
…or multi-threaded loading (also removed some unused headers from header files)
  • Loading branch information
PanosK92 committed Nov 24, 2024
1 parent 7e0c167 commit 9ef9473
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions editor/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =====
Expand Down
2 changes: 2 additions & 0 deletions editor/ImGui/ImGuiExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//= INCLUDES ======================
#include <string>
#include <variant>
#include "Definitions.h"
#include "Logging/Log.h"
#include "Window.h"
#include "RHI/RHI_Texture.h"
#include "Rendering/Renderer.h"
Expand Down
6 changes: 3 additions & 3 deletions runtime/RHI/RHI_Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions runtime/Rendering/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/Rendering/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

//= INCLUDES =====================
#include <vector>
#include <mutex>
#include "Material.h"
#include "../Resource/IResource.h"
#include "../Math/BoundingBox.h"
Expand Down
16 changes: 11 additions & 5 deletions runtime/Resource/IResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <atomic>
#include "../Core/FileSystem.h"
#include "../Core/SpartanObject.h"
#include "../Logging/Log.h"
//================================

namespace Spartan
Expand All @@ -44,6 +43,13 @@ namespace Spartan
Max,
};

enum class ResourceState
{
Processed,
Ready,
Max
};

class IResource : public SpartanObject
{
public:
Expand Down Expand Up @@ -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; }
Expand All @@ -106,9 +112,9 @@ namespace Spartan
static constexpr ResourceType TypeToEnum();

protected:
ResourceType m_resource_type = ResourceType::Max;
std::atomic<bool> m_is_gpu_ready = false;
uint32_t m_flags = 0;
ResourceType m_resource_type = ResourceType::Max;
std::atomic<ResourceState> m_resource_state = ResourceState::Max;
uint32_t m_flags = 0;

private:
std::string m_resource_directory;
Expand Down
5 changes: 3 additions & 2 deletions runtime/Resource/ResourceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ 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"
#include "../IO/FileStream.h"
#include "../RHI/RHI_Texture.h"
#include "../Audio/AudioClip.h"
#include "../Rendering/Mesh.h"
//===============================
#include "../Core/ProgressTracker.h"
//==================================

//= NAMESPACES ================
using namespace std;
Expand Down
7 changes: 3 additions & 4 deletions runtime/Resource/ResourceCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#pragma once

//= INCLUDES ===============
#include <algorithm>
//= INCLUDES ==============
#include "IResource.h"
#include "ProgressTracker.h"
//==========================
#include "../Logging/Log.h"
//=========================

namespace Spartan
{
Expand Down
1 change: 1 addition & 0 deletions runtime/World/Components/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===============
Expand Down

0 comments on commit 9ef9473

Please sign in to comment.