More http post end points filled
This commit is contained in:
224
apps/RenderCadenceCompositor/runtime/RuntimeLayerModel.cpp
Normal file
224
apps/RenderCadenceCompositor/runtime/RuntimeLayerModel.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
#include "RuntimeLayerModel.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace RenderCadenceCompositor
|
||||
{
|
||||
bool RuntimeLayerModel::InitializeSingleLayer(const SupportedShaderCatalog& shaderCatalog, const std::string& shaderId, std::string& error)
|
||||
{
|
||||
Clear();
|
||||
if (shaderId.empty())
|
||||
{
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
const ShaderPackage* shaderPackage = shaderCatalog.FindPackage(shaderId);
|
||||
if (!shaderPackage)
|
||||
{
|
||||
error = "Shader '" + shaderId + "' is not in the supported shader catalog.";
|
||||
return false;
|
||||
}
|
||||
|
||||
Layer layer;
|
||||
layer.id = AllocateLayerId();
|
||||
layer.shaderId = shaderPackage->id;
|
||||
layer.shaderName = shaderPackage->displayName.empty() ? shaderPackage->id : shaderPackage->displayName;
|
||||
layer.buildState = RuntimeLayerBuildState::Pending;
|
||||
layer.message = "Runtime Slang build is waiting to start.";
|
||||
mLayers.push_back(std::move(layer));
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::AddLayer(const SupportedShaderCatalog& shaderCatalog, const std::string& shaderId, std::string& layerId, std::string& error)
|
||||
{
|
||||
const ShaderPackage* shaderPackage = shaderCatalog.FindPackage(shaderId);
|
||||
if (!shaderPackage)
|
||||
{
|
||||
error = "Shader '" + shaderId + "' is not in the supported shader catalog.";
|
||||
return false;
|
||||
}
|
||||
|
||||
Layer layer;
|
||||
layer.id = AllocateLayerId();
|
||||
layer.shaderId = shaderPackage->id;
|
||||
layer.shaderName = shaderPackage->displayName.empty() ? shaderPackage->id : shaderPackage->displayName;
|
||||
layer.buildState = RuntimeLayerBuildState::Pending;
|
||||
layer.message = "Runtime Slang build is waiting to start.";
|
||||
layerId = layer.id;
|
||||
mLayers.push_back(std::move(layer));
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::RemoveLayer(const std::string& layerId, std::string& error)
|
||||
{
|
||||
for (auto layerIt = mLayers.begin(); layerIt != mLayers.end(); ++layerIt)
|
||||
{
|
||||
if (layerIt->id != layerId)
|
||||
continue;
|
||||
|
||||
mLayers.erase(layerIt);
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
error = "Unknown runtime layer id: " + layerId;
|
||||
return false;
|
||||
}
|
||||
|
||||
void RuntimeLayerModel::Clear()
|
||||
{
|
||||
mLayers.clear();
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::MarkBuildStarted(const std::string& layerId, const std::string& message, std::string& error)
|
||||
{
|
||||
Layer* layer = FindLayer(layerId);
|
||||
if (!layer)
|
||||
{
|
||||
error = "Unknown runtime layer id: " + layerId;
|
||||
return false;
|
||||
}
|
||||
|
||||
layer->buildState = RuntimeLayerBuildState::Pending;
|
||||
layer->message = message;
|
||||
layer->renderReady = false;
|
||||
layer->artifact = RuntimeShaderArtifact();
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::MarkBuildReady(const RuntimeShaderArtifact& artifact, std::string& error)
|
||||
{
|
||||
Layer* layer = artifact.layerId.empty() ? FindFirstLayerForShader(artifact.shaderId) : FindLayer(artifact.layerId);
|
||||
if (!layer)
|
||||
{
|
||||
error = artifact.layerId.empty()
|
||||
? "No runtime layer is waiting for shader artifact: " + artifact.shaderId
|
||||
: "No runtime layer is waiting for shader artifact on layer: " + artifact.layerId;
|
||||
return false;
|
||||
}
|
||||
|
||||
layer->shaderName = artifact.displayName.empty() ? artifact.shaderId : artifact.displayName;
|
||||
layer->buildState = RuntimeLayerBuildState::Ready;
|
||||
layer->message = artifact.message;
|
||||
layer->renderReady = true;
|
||||
layer->artifact = artifact;
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::MarkBuildFailedForShader(const std::string& shaderId, const std::string& message)
|
||||
{
|
||||
Layer* layer = FindFirstLayerForShader(shaderId);
|
||||
if (!layer)
|
||||
return false;
|
||||
|
||||
std::string error;
|
||||
return MarkBuildFailed(layer->id, message, error);
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::MarkBuildFailed(const std::string& layerId, const std::string& message, std::string& error)
|
||||
{
|
||||
Layer* layer = FindLayer(layerId);
|
||||
if (!layer)
|
||||
{
|
||||
error = "Unknown runtime layer id: " + layerId;
|
||||
return false;
|
||||
}
|
||||
|
||||
layer->buildState = RuntimeLayerBuildState::Failed;
|
||||
layer->message = message;
|
||||
layer->renderReady = false;
|
||||
layer->artifact = RuntimeShaderArtifact();
|
||||
error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeLayerModel::MarkRenderCommitFailed(const std::string& layerId, const std::string& message, std::string& error)
|
||||
{
|
||||
return MarkBuildFailed(layerId, message, error);
|
||||
}
|
||||
|
||||
RuntimeLayerModelSnapshot RuntimeLayerModel::Snapshot() const
|
||||
{
|
||||
RuntimeLayerModelSnapshot snapshot;
|
||||
snapshot.compileSucceeded = true;
|
||||
|
||||
for (const Layer& layer : mLayers)
|
||||
{
|
||||
snapshot.displayLayers.push_back(ToReadModel(layer));
|
||||
if (!layer.message.empty() && snapshot.compileMessage.empty())
|
||||
snapshot.compileMessage = layer.message;
|
||||
if (layer.buildState == RuntimeLayerBuildState::Failed)
|
||||
snapshot.compileSucceeded = false;
|
||||
if (layer.renderReady)
|
||||
{
|
||||
RuntimeRenderLayerModel renderLayer;
|
||||
renderLayer.id = layer.id;
|
||||
renderLayer.shaderId = layer.shaderId;
|
||||
renderLayer.artifact = layer.artifact;
|
||||
snapshot.renderLayers.push_back(std::move(renderLayer));
|
||||
}
|
||||
}
|
||||
|
||||
if (snapshot.compileMessage.empty())
|
||||
snapshot.compileMessage = mLayers.empty() ? "Runtime shader build disabled." : "Runtime shader build has not completed yet.";
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
std::string RuntimeLayerModel::FirstLayerId() const
|
||||
{
|
||||
return mLayers.empty() ? std::string() : mLayers.front().id;
|
||||
}
|
||||
|
||||
RuntimeLayerModel::Layer* RuntimeLayerModel::FindLayer(const std::string& layerId)
|
||||
{
|
||||
for (Layer& layer : mLayers)
|
||||
{
|
||||
if (layer.id == layerId)
|
||||
return &layer;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const RuntimeLayerModel::Layer* RuntimeLayerModel::FindLayer(const std::string& layerId) const
|
||||
{
|
||||
for (const Layer& layer : mLayers)
|
||||
{
|
||||
if (layer.id == layerId)
|
||||
return &layer;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RuntimeLayerModel::Layer* RuntimeLayerModel::FindFirstLayerForShader(const std::string& shaderId)
|
||||
{
|
||||
for (Layer& layer : mLayers)
|
||||
{
|
||||
if (layer.shaderId == shaderId)
|
||||
return &layer;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string RuntimeLayerModel::AllocateLayerId()
|
||||
{
|
||||
return "runtime-layer-" + std::to_string(mNextLayerNumber++);
|
||||
}
|
||||
|
||||
RuntimeLayerReadModel RuntimeLayerModel::ToReadModel(const Layer& layer)
|
||||
{
|
||||
RuntimeLayerReadModel readModel;
|
||||
readModel.id = layer.id;
|
||||
readModel.shaderId = layer.shaderId;
|
||||
readModel.shaderName = layer.shaderName;
|
||||
readModel.bypass = layer.bypass;
|
||||
readModel.buildState = layer.buildState;
|
||||
readModel.message = layer.message;
|
||||
readModel.renderReady = layer.renderReady;
|
||||
return readModel;
|
||||
}
|
||||
}
|
||||
84
apps/RenderCadenceCompositor/runtime/RuntimeLayerModel.h
Normal file
84
apps/RenderCadenceCompositor/runtime/RuntimeLayerModel.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "RuntimeShaderArtifact.h"
|
||||
#include "SupportedShaderCatalog.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace RenderCadenceCompositor
|
||||
{
|
||||
enum class RuntimeLayerBuildState
|
||||
{
|
||||
Pending,
|
||||
Ready,
|
||||
Failed
|
||||
};
|
||||
|
||||
struct RuntimeLayerReadModel
|
||||
{
|
||||
std::string id;
|
||||
std::string shaderId;
|
||||
std::string shaderName;
|
||||
bool bypass = false;
|
||||
RuntimeLayerBuildState buildState = RuntimeLayerBuildState::Pending;
|
||||
std::string message;
|
||||
bool renderReady = false;
|
||||
};
|
||||
|
||||
struct RuntimeRenderLayerModel
|
||||
{
|
||||
std::string id;
|
||||
std::string shaderId;
|
||||
RuntimeShaderArtifact artifact;
|
||||
};
|
||||
|
||||
struct RuntimeLayerModelSnapshot
|
||||
{
|
||||
bool compileSucceeded = true;
|
||||
std::string compileMessage;
|
||||
std::vector<RuntimeLayerReadModel> displayLayers;
|
||||
std::vector<RuntimeRenderLayerModel> renderLayers;
|
||||
};
|
||||
|
||||
class RuntimeLayerModel
|
||||
{
|
||||
public:
|
||||
bool InitializeSingleLayer(const SupportedShaderCatalog& shaderCatalog, const std::string& shaderId, std::string& error);
|
||||
void Clear();
|
||||
|
||||
bool AddLayer(const SupportedShaderCatalog& shaderCatalog, const std::string& shaderId, std::string& layerId, std::string& error);
|
||||
bool RemoveLayer(const std::string& layerId, std::string& error);
|
||||
bool MarkBuildStarted(const std::string& layerId, const std::string& message, std::string& error);
|
||||
bool MarkBuildReady(const RuntimeShaderArtifact& artifact, std::string& error);
|
||||
bool MarkBuildFailedForShader(const std::string& shaderId, const std::string& message);
|
||||
bool MarkBuildFailed(const std::string& layerId, const std::string& message, std::string& error);
|
||||
bool MarkRenderCommitFailed(const std::string& layerId, const std::string& message, std::string& error);
|
||||
|
||||
RuntimeLayerModelSnapshot Snapshot() const;
|
||||
std::string FirstLayerId() const;
|
||||
|
||||
private:
|
||||
struct Layer
|
||||
{
|
||||
std::string id;
|
||||
std::string shaderId;
|
||||
std::string shaderName;
|
||||
bool bypass = false;
|
||||
RuntimeLayerBuildState buildState = RuntimeLayerBuildState::Pending;
|
||||
std::string message;
|
||||
bool renderReady = false;
|
||||
RuntimeShaderArtifact artifact;
|
||||
};
|
||||
|
||||
Layer* FindLayer(const std::string& layerId);
|
||||
const Layer* FindLayer(const std::string& layerId) const;
|
||||
Layer* FindFirstLayerForShader(const std::string& shaderId);
|
||||
std::string AllocateLayerId();
|
||||
static RuntimeLayerReadModel ToReadModel(const Layer& layer);
|
||||
|
||||
std::vector<Layer> mLayers;
|
||||
uint64_t mNextLayerNumber = 1;
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
struct RuntimeShaderArtifact
|
||||
{
|
||||
std::string layerId;
|
||||
std::string shaderId;
|
||||
std::string displayName;
|
||||
std::string fragmentShaderSource;
|
||||
|
||||
@@ -8,11 +8,17 @@ RuntimeShaderBridge::~RuntimeShaderBridge()
|
||||
}
|
||||
|
||||
void RuntimeShaderBridge::Start(const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError)
|
||||
{
|
||||
Start(std::string(), shaderId, std::move(onArtifactReady), std::move(onError));
|
||||
}
|
||||
|
||||
void RuntimeShaderBridge::Start(const std::string& layerId, const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError)
|
||||
{
|
||||
Stop();
|
||||
if (shaderId.empty())
|
||||
return;
|
||||
|
||||
mLayerId = layerId;
|
||||
mOnArtifactReady = std::move(onArtifactReady);
|
||||
mOnError = std::move(onError);
|
||||
mStopping.store(false, std::memory_order_release);
|
||||
@@ -26,6 +32,7 @@ void RuntimeShaderBridge::Stop()
|
||||
if (mThread.joinable())
|
||||
mThread.join();
|
||||
mCompiler.Stop();
|
||||
mLayerId.clear();
|
||||
mOnArtifactReady = ArtifactCallback();
|
||||
mOnError = ErrorCallback();
|
||||
}
|
||||
@@ -39,6 +46,7 @@ void RuntimeShaderBridge::ThreadMain()
|
||||
{
|
||||
if (build.succeeded)
|
||||
{
|
||||
build.artifact.layerId = mLayerId;
|
||||
if (mOnArtifactReady)
|
||||
mOnArtifactReady(build.artifact);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
~RuntimeShaderBridge();
|
||||
|
||||
void Start(const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
|
||||
void Start(const std::string& layerId, const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
@@ -28,6 +29,7 @@ private:
|
||||
RuntimeSlangShaderCompiler mCompiler;
|
||||
std::thread mThread;
|
||||
std::atomic<bool> mStopping{ false };
|
||||
std::string mLayerId;
|
||||
ArtifactCallback mOnArtifactReady;
|
||||
ErrorCallback mOnError;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user