runtime read of json layer state
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#include "RuntimeLayerController.h"
|
||||
|
||||
#include "AppConfigProvider.h"
|
||||
#include "RuntimeJson.h"
|
||||
#include "../logging/Logger.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace RenderCadenceCompositor
|
||||
{
|
||||
@@ -30,6 +33,9 @@ bool RuntimeLayerController::LoadSupportedShaderCatalog(const std::string& shade
|
||||
|
||||
void RuntimeLayerController::InitializeLayerModel(std::string& runtimeShaderId)
|
||||
{
|
||||
if (InitializeLayerModelFromRuntimeState())
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(mRuntimeLayerMutex);
|
||||
std::string error;
|
||||
if (!mRuntimeLayerModel.InitializeSingleLayer(mShaderCatalog, runtimeShaderId, error))
|
||||
@@ -40,6 +46,43 @@ void RuntimeLayerController::InitializeLayerModel(std::string& runtimeShaderId)
|
||||
}
|
||||
}
|
||||
|
||||
bool RuntimeLayerController::InitializeLayerModelFromRuntimeState()
|
||||
{
|
||||
const std::filesystem::path runtimeStatePath = FindRepoPath("runtime/runtime_state.json");
|
||||
if (runtimeStatePath.empty())
|
||||
return false;
|
||||
|
||||
std::ifstream input(runtimeStatePath, std::ios::binary);
|
||||
if (!input)
|
||||
{
|
||||
LogWarning("runtime-state", "Could not open runtime state file: " + runtimeStatePath.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostringstream buffer;
|
||||
buffer << input.rdbuf();
|
||||
|
||||
JsonValue runtimeState;
|
||||
std::string error;
|
||||
if (!ParseJson(buffer.str(), runtimeState, error))
|
||||
{
|
||||
LogWarning("runtime-state", "Could not parse runtime state file: " + error);
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mRuntimeLayerMutex);
|
||||
if (!mRuntimeLayerModel.InitializeFromRuntimeState(mShaderCatalog, runtimeState, error))
|
||||
{
|
||||
LogWarning("runtime-state", "Could not restore runtime state: " + error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Log("runtime-state", "Restored runtime layer stack from " + runtimeStatePath.string() + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
void RuntimeLayerController::StartLayerShaderBuild(const std::string& layerId, const std::string& shaderId)
|
||||
{
|
||||
CleanupRetiredShaderBuilds();
|
||||
|
||||
Reference in New Issue
Block a user