Files
video-shader-toys/apps/RenderCadenceCompositor/app/RuntimeLayerController.h
Aiden c5fd8e72b4
All checks were successful
CI / React UI Build (push) Successful in 11s
CI / Native Windows Build And Tests (push) Successful in 2m58s
CI / Windows Release Package (push) Has been skipped
non-blocking http
2026-05-12 15:05:54 +10:00

62 lines
2.3 KiB
C++

#pragma once
#include "../control/ControlActionResult.h"
#include "../runtime/RuntimeLayerModel.h"
#include "../runtime/RuntimeShaderBridge.h"
#include "../runtime/SupportedShaderCatalog.h"
#include "../telemetry/CadenceTelemetry.h"
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace RenderCadenceCompositor
{
class RuntimeLayerController
{
public:
using RenderLayerPublisher = std::function<void(const std::vector<RuntimeRenderLayerModel>&)>;
explicit RuntimeLayerController(RenderLayerPublisher publisher = RenderLayerPublisher());
RuntimeLayerController(const RuntimeLayerController&) = delete;
RuntimeLayerController& operator=(const RuntimeLayerController&) = delete;
~RuntimeLayerController();
void SetPublisher(RenderLayerPublisher publisher);
void Initialize(const std::string& shaderLibrary, unsigned maxTemporalHistoryFrames, std::string& runtimeShaderId);
void StartStartupBuild(const std::string& runtimeShaderId);
void Stop();
ControlActionResult HandleAddLayer(const std::string& body);
ControlActionResult HandleRemoveLayer(const std::string& body);
RuntimeLayerModelSnapshot Snapshot(const CadenceTelemetrySnapshot& telemetry) const;
const SupportedShaderCatalog& ShaderCatalog() const { return mShaderCatalog; }
private:
void LoadSupportedShaderCatalog(const std::string& shaderLibrary, unsigned maxTemporalHistoryFrames);
void InitializeLayerModel(std::string& runtimeShaderId);
void StartLayerShaderBuild(const std::string& layerId, const std::string& shaderId);
void RetireLayerShaderBuild(const std::string& layerId);
void CleanupRetiredShaderBuilds();
void StopAllRuntimeShaderBuilds();
void PublishRuntimeRenderLayers();
bool MarkRuntimeBuildReady(const RuntimeShaderArtifact& artifact);
void MarkRuntimeBuildFailedForLayer(const std::string& layerId, const std::string& message);
std::string FirstRuntimeLayerId() const;
static bool ExtractStringField(const std::string& body, const char* fieldName, std::string& value, std::string& error);
RenderLayerPublisher mPublisher;
SupportedShaderCatalog mShaderCatalog;
mutable std::mutex mRuntimeLayerMutex;
RuntimeLayerModel mRuntimeLayerModel;
std::mutex mShaderBuildMutex;
std::map<std::string, std::unique_ptr<RuntimeShaderBridge>> mShaderBuilds;
std::vector<std::unique_ptr<RuntimeShaderBridge>> mRetiredShaderBuilds;
};
}