runtime read of json layer state

This commit is contained in:
2026-05-21 16:08:46 +10:00
parent c2de2c3738
commit bda9a9dc22
6 changed files with 245 additions and 5 deletions

View File

@@ -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();