#include "RuntimeLayerController.h" #include "../logging/Logger.h" namespace RenderCadenceCompositor { RuntimeLayerController::RuntimeLayerController(RenderLayerPublisher publisher) : mPublisher(std::move(publisher)) { } RuntimeLayerController::~RuntimeLayerController() { Stop(); } void RuntimeLayerController::SetPublisher(RenderLayerPublisher publisher) { mPublisher = std::move(publisher); } void RuntimeLayerController::Initialize(const std::string& shaderLibrary, unsigned maxTemporalHistoryFrames, std::string& runtimeShaderId) { LoadSupportedShaderCatalog(shaderLibrary, maxTemporalHistoryFrames); InitializeLayerModel(runtimeShaderId); } void RuntimeLayerController::StartStartupBuild(const std::string& runtimeShaderId) { if (runtimeShaderId.empty()) { Log("runtime-shader", "Runtime shader build disabled."); return; } Log("runtime-shader", "Starting background Slang build for shader '" + runtimeShaderId + "'."); const std::string layerId = FirstRuntimeLayerId(); if (!layerId.empty()) StartLayerShaderBuild(layerId, runtimeShaderId); } void RuntimeLayerController::Stop() { StopAllRuntimeShaderBuilds(); } RuntimeLayerModelSnapshot RuntimeLayerController::Snapshot(const CadenceTelemetrySnapshot& telemetry) const { std::lock_guard lock(mRuntimeLayerMutex); RuntimeLayerModelSnapshot snapshot = mRuntimeLayerModel.Snapshot(); if (telemetry.shaderBuildFailures > 0) { snapshot.compileSucceeded = false; snapshot.compileMessage = "Runtime shader GL commit failed; see logs for details."; } return snapshot; } void RuntimeLayerController::PublishRuntimeRenderLayers() { if (!mPublisher) return; std::vector renderLayers; { std::lock_guard lock(mRuntimeLayerMutex); renderLayers = mRuntimeLayerModel.Snapshot().renderLayers; } mPublisher(renderLayers); } bool RuntimeLayerController::MarkRuntimeBuildReady(const RuntimeShaderArtifact& artifact) { std::lock_guard lock(mRuntimeLayerMutex); std::string error; if (!mRuntimeLayerModel.MarkBuildReady(artifact, error)) { LogWarning("runtime-shader", error); return false; } return true; } void RuntimeLayerController::MarkRuntimeBuildFailedForLayer(const std::string& layerId, const std::string& message) { std::lock_guard lock(mRuntimeLayerMutex); std::string error; if (!mRuntimeLayerModel.MarkBuildFailed(layerId, message, error)) LogWarning("runtime-shader", error); } }