dispatch event intergration
This commit is contained in:
@@ -1,8 +1,27 @@
|
||||
#include "RuntimeCoordinator.h"
|
||||
|
||||
#include "RuntimeEventDispatcher.h"
|
||||
#include "RuntimeEventPayloads.h"
|
||||
#include "RuntimeParameterUtils.h"
|
||||
#include "RuntimeStore.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
RuntimeEventRenderResetScope ToRuntimeEventRenderResetScope(RuntimeCoordinatorRenderResetScope scope)
|
||||
{
|
||||
switch (scope)
|
||||
{
|
||||
case RuntimeCoordinatorRenderResetScope::TemporalHistoryOnly:
|
||||
return RuntimeEventRenderResetScope::TemporalHistoryOnly;
|
||||
case RuntimeCoordinatorRenderResetScope::TemporalHistoryAndFeedback:
|
||||
return RuntimeEventRenderResetScope::TemporalHistoryAndFeedback;
|
||||
case RuntimeCoordinatorRenderResetScope::None:
|
||||
default:
|
||||
return RuntimeEventRenderResetScope::None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeCoordinator::RuntimeCoordinator(RuntimeStore& runtimeStore, RuntimeEventDispatcher& runtimeEventDispatcher) :
|
||||
mRuntimeStore(runtimeStore),
|
||||
mRuntimeEventDispatcher(runtimeEventDispatcher)
|
||||
@@ -14,9 +33,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::AddLayer(const std::string& shaderI
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidateShaderExists(shaderId, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("AddLayer", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.CreateStoredLayer(shaderId, error), error, true, true);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.CreateStoredLayer(shaderId, error), error, true, true);
|
||||
PublishCoordinatorResult("AddLayer", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::RemoveLayer(const std::string& layerId)
|
||||
@@ -24,9 +49,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::RemoveLayer(const std::string& laye
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidateLayerExists(layerId, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("RemoveLayer", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.DeleteStoredLayer(layerId, error), error, true, true);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.DeleteStoredLayer(layerId, error), error, true, true);
|
||||
PublishCoordinatorResult("RemoveLayer", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::MoveLayer(const std::string& layerId, int direction)
|
||||
@@ -35,11 +66,20 @@ RuntimeCoordinatorResult RuntimeCoordinator::MoveLayer(const std::string& layerI
|
||||
std::string error;
|
||||
bool shouldMove = false;
|
||||
if (!ResolveLayerMove(layerId, direction, shouldMove, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("MoveLayer", result);
|
||||
return result;
|
||||
}
|
||||
if (!shouldMove)
|
||||
return BuildAcceptedNoReloadResult();
|
||||
{
|
||||
RuntimeCoordinatorResult result = BuildAcceptedNoReloadResult();
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.MoveStoredLayer(layerId, direction, error), error, true, true);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.MoveStoredLayer(layerId, direction, error), error, true, true);
|
||||
PublishCoordinatorResult("MoveLayer", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::MoveLayerToIndex(const std::string& layerId, std::size_t targetIndex)
|
||||
@@ -48,11 +88,20 @@ RuntimeCoordinatorResult RuntimeCoordinator::MoveLayerToIndex(const std::string&
|
||||
std::string error;
|
||||
bool shouldMove = false;
|
||||
if (!ResolveLayerMoveToIndex(layerId, targetIndex, shouldMove, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("MoveLayerToIndex", result);
|
||||
return result;
|
||||
}
|
||||
if (!shouldMove)
|
||||
return BuildAcceptedNoReloadResult();
|
||||
{
|
||||
RuntimeCoordinatorResult result = BuildAcceptedNoReloadResult();
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.MoveStoredLayerToIndex(layerId, targetIndex, error), error, true, true);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.MoveStoredLayerToIndex(layerId, targetIndex, error), error, true, true);
|
||||
PublishCoordinatorResult("MoveLayerToIndex", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::SetLayerBypass(const std::string& layerId, bool bypassed)
|
||||
@@ -60,9 +109,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::SetLayerBypass(const std::string& l
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidateLayerExists(layerId, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("SetLayerBypass", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.SetStoredLayerBypassState(layerId, bypassed, error), error, true, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.SetStoredLayerBypassState(layerId, bypassed, error), error, true, false);
|
||||
PublishCoordinatorResult("SetLayerBypass", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::SetLayerShader(const std::string& layerId, const std::string& shaderId)
|
||||
@@ -70,9 +125,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::SetLayerShader(const std::string& l
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidateLayerExists(layerId, error) || !ValidateShaderExists(shaderId, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("SetLayerShader", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.SetStoredLayerShaderSelection(layerId, shaderId, error), error, true, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.SetStoredLayerShaderSelection(layerId, shaderId, error), error, true, false);
|
||||
PublishCoordinatorResult("SetLayerShader", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::UpdateLayerParameter(const std::string& layerId, const std::string& parameterId, const JsonValue& newValue)
|
||||
@@ -81,9 +142,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::UpdateLayerParameter(const std::str
|
||||
std::string error;
|
||||
ResolvedParameterMutation mutation;
|
||||
if (!BuildParameterMutationById(layerId, parameterId, newValue, true, mutation, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("UpdateLayerParameter", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.SetStoredParameterValue(mutation.layerId, mutation.parameterId, mutation.value, mutation.persistState, error), error, false, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.SetStoredParameterValue(mutation.layerId, mutation.parameterId, mutation.value, mutation.persistState, error), error, false, false);
|
||||
PublishCoordinatorResult("UpdateLayerParameter", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::UpdateLayerParameterByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue)
|
||||
@@ -92,9 +159,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::UpdateLayerParameterByControlKey(co
|
||||
std::string error;
|
||||
ResolvedParameterMutation mutation;
|
||||
if (!BuildParameterMutationByControlKey(layerKey, parameterKey, newValue, true, mutation, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("UpdateLayerParameterByControlKey", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.SetStoredParameterValue(mutation.layerId, mutation.parameterId, mutation.value, mutation.persistState, error), error, false, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.SetStoredParameterValue(mutation.layerId, mutation.parameterId, mutation.value, mutation.persistState, error), error, false, false);
|
||||
PublishCoordinatorResult("UpdateLayerParameterByControlKey", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::CommitOscParameterByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue)
|
||||
@@ -103,9 +176,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::CommitOscParameterByControlKey(cons
|
||||
std::string error;
|
||||
ResolvedParameterMutation mutation;
|
||||
if (!BuildParameterMutationByControlKey(layerKey, parameterKey, newValue, false, mutation, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("CommitOscParameterByControlKey", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.SetStoredParameterValue(mutation.layerId, mutation.parameterId, mutation.value, mutation.persistState, error), error, false, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.SetStoredParameterValue(mutation.layerId, mutation.parameterId, mutation.value, mutation.persistState, error), error, false, false);
|
||||
PublishCoordinatorResult("CommitOscParameterByControlKey", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::ResetLayerParameters(const std::string& layerId)
|
||||
@@ -113,14 +192,22 @@ RuntimeCoordinatorResult RuntimeCoordinator::ResetLayerParameters(const std::str
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidateLayerExists(layerId, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("ResetLayerParameters", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.ResetStoredLayerParameterValues(layerId, error), error, false, false);
|
||||
if (!result.accepted)
|
||||
{
|
||||
PublishCoordinatorResult("ResetLayerParameters", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.clearTransientOscState = true;
|
||||
result.renderResetScope = RuntimeCoordinatorRenderResetScope::TemporalHistoryAndFeedback;
|
||||
PublishCoordinatorResult("ResetLayerParameters", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -129,9 +216,15 @@ RuntimeCoordinatorResult RuntimeCoordinator::SaveStackPreset(const std::string&
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidatePresetName(presetName, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("SaveStackPreset", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.SaveStackPresetSnapshot(presetName, error), error, false, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.SaveStackPresetSnapshot(presetName, error), error, false, false);
|
||||
PublishCoordinatorResult("SaveStackPreset", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::LoadStackPreset(const std::string& presetName)
|
||||
@@ -139,15 +232,23 @@ RuntimeCoordinatorResult RuntimeCoordinator::LoadStackPreset(const std::string&
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
if (!ValidatePresetName(presetName, error))
|
||||
return ApplyStoreMutation(false, error, false, false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false);
|
||||
PublishCoordinatorResult("LoadStackPreset", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return ApplyStoreMutation(mRuntimeStore.LoadStackPresetSnapshot(presetName, error), error, true, false);
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(mRuntimeStore.LoadStackPresetSnapshot(presetName, error), error, true, false);
|
||||
PublishCoordinatorResult("LoadStackPreset", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::RequestShaderReload(bool preserveFeedbackState)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
return BuildQueuedReloadResult(preserveFeedbackState);
|
||||
RuntimeCoordinatorResult result = BuildQueuedReloadResult(preserveFeedbackState);
|
||||
PublishCoordinatorFollowUpEvents("RequestShaderReload", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::PollRuntimeStoreChanges(bool& registryChanged)
|
||||
@@ -158,13 +259,24 @@ RuntimeCoordinatorResult RuntimeCoordinator::PollRuntimeStoreChanges(bool& regis
|
||||
bool reloadRequested = false;
|
||||
std::string error;
|
||||
if (!mRuntimeStore.PollStoredFileChanges(registryChanged, reloadRequested, error))
|
||||
return HandleRuntimePollFailure(error);
|
||||
{
|
||||
RuntimeCoordinatorResult result = HandleRuntimePollFailure(error);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (reloadRequested)
|
||||
return BuildQueuedReloadResult(false);
|
||||
{
|
||||
RuntimeCoordinatorResult result = BuildQueuedReloadResult(false);
|
||||
PublishCoordinatorFollowUpEvents("PollRuntimeStoreChanges", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (registryChanged)
|
||||
return BuildAcceptedNoReloadResult();
|
||||
{
|
||||
RuntimeCoordinatorResult result = BuildAcceptedNoReloadResult();
|
||||
PublishCoordinatorFollowUpEvents("PollRuntimeStoreChanges", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult result;
|
||||
result.accepted = true;
|
||||
@@ -179,6 +291,7 @@ RuntimeCoordinatorResult RuntimeCoordinator::HandleRuntimePollFailure(const std:
|
||||
result.compileStatusChanged = true;
|
||||
result.compileStatusSucceeded = false;
|
||||
result.compileStatusMessage = error;
|
||||
PublishCoordinatorFollowUpEvents("HandleRuntimePollFailure", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -195,6 +308,7 @@ RuntimeCoordinatorResult RuntimeCoordinator::HandlePreparedShaderBuildFailure(co
|
||||
result.compileStatusSucceeded = false;
|
||||
result.compileStatusMessage = error;
|
||||
result.committedStateMode = RuntimeCoordinatorCommittedStateMode::UseCommittedStates;
|
||||
PublishCoordinatorFollowUpEvents("HandlePreparedShaderBuildFailure", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -211,13 +325,16 @@ RuntimeCoordinatorResult RuntimeCoordinator::HandlePreparedShaderBuildSuccess()
|
||||
result.compileStatusMessage = "Shader layers compiled successfully.";
|
||||
result.committedStateMode = RuntimeCoordinatorCommittedStateMode::UseLiveSnapshots;
|
||||
mPreserveFeedbackOnNextShaderBuild = false;
|
||||
PublishCoordinatorFollowUpEvents("HandlePreparedShaderBuildSuccess", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
RuntimeCoordinatorResult RuntimeCoordinator::HandleRuntimeReloadRequest()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
return BuildQueuedReloadResult(false);
|
||||
RuntimeCoordinatorResult result = BuildQueuedReloadResult(false);
|
||||
PublishCoordinatorFollowUpEvents("HandleRuntimeReloadRequest", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void RuntimeCoordinator::ApplyCommittedStateMode(RuntimeCoordinatorCommittedStateMode mode)
|
||||
@@ -369,3 +486,68 @@ RuntimeCoordinatorResult RuntimeCoordinator::BuildAcceptedNoReloadResult() const
|
||||
result.runtimeStateBroadcastRequired = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
void RuntimeCoordinator::PublishCoordinatorResult(const std::string& action, const RuntimeCoordinatorResult& result) const
|
||||
{
|
||||
try
|
||||
{
|
||||
RuntimeMutationEvent mutation;
|
||||
mutation.action = action;
|
||||
mutation.accepted = result.accepted;
|
||||
mutation.runtimeStateChanged = result.accepted && result.runtimeStateBroadcastRequired;
|
||||
mutation.runtimeStateBroadcastRequired = result.runtimeStateBroadcastRequired;
|
||||
mutation.shaderBuildRequested = result.shaderBuildRequested;
|
||||
mutation.clearTransientOscState = result.clearTransientOscState;
|
||||
mutation.renderResetScope = ToRuntimeEventRenderResetScope(result.renderResetScope);
|
||||
mutation.errorMessage = result.errorMessage;
|
||||
mRuntimeEventDispatcher.PublishPayload(mutation, "RuntimeCoordinator");
|
||||
|
||||
PublishCoordinatorFollowUpEvents(action, result);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeCoordinator::PublishCoordinatorFollowUpEvents(const std::string& action, const RuntimeCoordinatorResult& result) const
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!result.accepted)
|
||||
return;
|
||||
|
||||
if (result.runtimeStateBroadcastRequired)
|
||||
{
|
||||
RuntimeStateChangedEvent stateChanged;
|
||||
stateChanged.reason = action;
|
||||
stateChanged.renderVisible = result.renderResetScope != RuntimeCoordinatorRenderResetScope::None;
|
||||
mRuntimeEventDispatcher.PublishPayload(stateChanged, "RuntimeCoordinator");
|
||||
}
|
||||
|
||||
if (result.shaderBuildRequested)
|
||||
{
|
||||
RuntimeReloadRequestedEvent reloadRequested;
|
||||
reloadRequested.preserveFeedbackState = mPreserveFeedbackOnNextShaderBuild;
|
||||
reloadRequested.reason = action;
|
||||
mRuntimeEventDispatcher.PublishPayload(reloadRequested, "RuntimeCoordinator");
|
||||
|
||||
ShaderBuildEvent shaderBuild;
|
||||
shaderBuild.phase = RuntimeEventShaderBuildPhase::Requested;
|
||||
shaderBuild.preserveFeedbackState = mPreserveFeedbackOnNextShaderBuild;
|
||||
shaderBuild.succeeded = true;
|
||||
shaderBuild.message = result.compileStatusMessage;
|
||||
mRuntimeEventDispatcher.PublishPayload(shaderBuild, "RuntimeCoordinator");
|
||||
}
|
||||
|
||||
if (result.compileStatusChanged)
|
||||
{
|
||||
CompileStatusChangedEvent compileStatus;
|
||||
compileStatus.succeeded = result.compileStatusSucceeded;
|
||||
compileStatus.message = result.compileStatusMessage;
|
||||
mRuntimeEventDispatcher.PublishPayload(compileStatus, "RuntimeCoordinator");
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ private:
|
||||
RuntimeCoordinatorResult ApplyStoreMutation(bool succeeded, const std::string& errorMessage, bool reloadRequired, bool preserveFeedbackState);
|
||||
RuntimeCoordinatorResult BuildQueuedReloadResult(bool preserveFeedbackState);
|
||||
RuntimeCoordinatorResult BuildAcceptedNoReloadResult() const;
|
||||
void PublishCoordinatorResult(const std::string& action, const RuntimeCoordinatorResult& result) const;
|
||||
void PublishCoordinatorFollowUpEvents(const std::string& action, const RuntimeCoordinatorResult& result) const;
|
||||
|
||||
RuntimeStore& mRuntimeStore;
|
||||
RuntimeEventDispatcher& mRuntimeEventDispatcher;
|
||||
|
||||
@@ -13,6 +13,7 @@ struct RuntimeEventDispatchResult
|
||||
std::size_t dispatchedEvents = 0;
|
||||
std::size_t handlerInvocations = 0;
|
||||
std::size_t handlerFailures = 0;
|
||||
double dispatchDurationMilliseconds = 0.0;
|
||||
};
|
||||
|
||||
class RuntimeEventDispatcher
|
||||
@@ -56,6 +57,7 @@ public:
|
||||
|
||||
RuntimeEventDispatchResult DispatchPending(std::size_t maxEvents = 0)
|
||||
{
|
||||
const auto startedAt = std::chrono::steady_clock::now();
|
||||
RuntimeEventDispatchResult result;
|
||||
std::vector<RuntimeEvent> events = mQueue.Drain(maxEvents);
|
||||
result.dispatchedEvents = events.size();
|
||||
@@ -78,6 +80,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
result.dispatchDurationMilliseconds =
|
||||
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - startedAt).count();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ struct RuntimeStatePresentationChangedEvent
|
||||
struct ShaderBuildEvent
|
||||
{
|
||||
RuntimeEventShaderBuildPhase phase = RuntimeEventShaderBuildPhase::Requested;
|
||||
uint64_t generation = 0;
|
||||
unsigned inputWidth = 0;
|
||||
unsigned inputHeight = 0;
|
||||
bool preserveFeedbackState = false;
|
||||
|
||||
@@ -80,6 +80,26 @@ JsonValue RuntimeStatePresenter::BuildRuntimeStateValue(const RuntimeStore& runt
|
||||
performance.set("flushedFrameCount", JsonValue(static_cast<double>(telemetrySnapshot.performance.flushedFrameCount)));
|
||||
root.set("performance", performance);
|
||||
|
||||
JsonValue eventQueue = JsonValue::MakeObject();
|
||||
eventQueue.set("name", JsonValue(telemetrySnapshot.runtimeEvents.queue.queueName));
|
||||
eventQueue.set("depth", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.queue.depth)));
|
||||
eventQueue.set("capacity", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.queue.capacity)));
|
||||
eventQueue.set("droppedCount", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.queue.droppedCount)));
|
||||
eventQueue.set("oldestEventAgeMs", JsonValue(telemetrySnapshot.runtimeEvents.queue.oldestEventAgeMilliseconds));
|
||||
|
||||
JsonValue eventDispatch = JsonValue::MakeObject();
|
||||
eventDispatch.set("dispatchCallCount", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.dispatch.dispatchCallCount)));
|
||||
eventDispatch.set("dispatchedEventCount", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.dispatch.dispatchedEventCount)));
|
||||
eventDispatch.set("handlerInvocationCount", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.dispatch.handlerInvocationCount)));
|
||||
eventDispatch.set("handlerFailureCount", JsonValue(static_cast<double>(telemetrySnapshot.runtimeEvents.dispatch.handlerFailureCount)));
|
||||
eventDispatch.set("lastDispatchDurationMs", JsonValue(telemetrySnapshot.runtimeEvents.dispatch.lastDispatchDurationMilliseconds));
|
||||
eventDispatch.set("maxDispatchDurationMs", JsonValue(telemetrySnapshot.runtimeEvents.dispatch.maxDispatchDurationMilliseconds));
|
||||
|
||||
JsonValue runtimeEvents = JsonValue::MakeObject();
|
||||
runtimeEvents.set("queue", eventQueue);
|
||||
runtimeEvents.set("dispatch", eventDispatch);
|
||||
root.set("runtimeEvents", runtimeEvents);
|
||||
|
||||
JsonValue shaderLibrary = JsonValue::MakeArray();
|
||||
for (const ShaderPackageStatus& status : model.packageStatuses)
|
||||
{
|
||||
|
||||
@@ -111,6 +111,64 @@ bool HealthTelemetry::TryRecordFramePacingStats(double completionIntervalMillise
|
||||
return true;
|
||||
}
|
||||
|
||||
void HealthTelemetry::RecordRuntimeEventQueueMetrics(const std::string& queueName, std::size_t depth, std::size_t capacity,
|
||||
uint64_t droppedCount, double oldestEventAgeMilliseconds)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
mRuntimeEvents.queue.queueName = queueName;
|
||||
mRuntimeEvents.queue.depth = depth;
|
||||
mRuntimeEvents.queue.capacity = capacity;
|
||||
mRuntimeEvents.queue.droppedCount = droppedCount;
|
||||
mRuntimeEvents.queue.oldestEventAgeMilliseconds = std::max(oldestEventAgeMilliseconds, 0.0);
|
||||
}
|
||||
|
||||
bool HealthTelemetry::TryRecordRuntimeEventQueueMetrics(const std::string& queueName, std::size_t depth, std::size_t capacity,
|
||||
uint64_t droppedCount, double oldestEventAgeMilliseconds)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex, std::try_to_lock);
|
||||
if (!lock.owns_lock())
|
||||
return false;
|
||||
|
||||
mRuntimeEvents.queue.queueName = queueName;
|
||||
mRuntimeEvents.queue.depth = depth;
|
||||
mRuntimeEvents.queue.capacity = capacity;
|
||||
mRuntimeEvents.queue.droppedCount = droppedCount;
|
||||
mRuntimeEvents.queue.oldestEventAgeMilliseconds = std::max(oldestEventAgeMilliseconds, 0.0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HealthTelemetry::RecordRuntimeEventDispatchStats(std::size_t dispatchedEvents, std::size_t handlerInvocations,
|
||||
std::size_t handlerFailures, double dispatchDurationMilliseconds)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
++mRuntimeEvents.dispatch.dispatchCallCount;
|
||||
mRuntimeEvents.dispatch.dispatchedEventCount += static_cast<uint64_t>(dispatchedEvents);
|
||||
mRuntimeEvents.dispatch.handlerInvocationCount += static_cast<uint64_t>(handlerInvocations);
|
||||
mRuntimeEvents.dispatch.handlerFailureCount += static_cast<uint64_t>(handlerFailures);
|
||||
mRuntimeEvents.dispatch.lastDispatchDurationMilliseconds = std::max(dispatchDurationMilliseconds, 0.0);
|
||||
mRuntimeEvents.dispatch.maxDispatchDurationMilliseconds = std::max(
|
||||
mRuntimeEvents.dispatch.maxDispatchDurationMilliseconds,
|
||||
mRuntimeEvents.dispatch.lastDispatchDurationMilliseconds);
|
||||
}
|
||||
|
||||
bool HealthTelemetry::TryRecordRuntimeEventDispatchStats(std::size_t dispatchedEvents, std::size_t handlerInvocations,
|
||||
std::size_t handlerFailures, double dispatchDurationMilliseconds)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mMutex, std::try_to_lock);
|
||||
if (!lock.owns_lock())
|
||||
return false;
|
||||
|
||||
++mRuntimeEvents.dispatch.dispatchCallCount;
|
||||
mRuntimeEvents.dispatch.dispatchedEventCount += static_cast<uint64_t>(dispatchedEvents);
|
||||
mRuntimeEvents.dispatch.handlerInvocationCount += static_cast<uint64_t>(handlerInvocations);
|
||||
mRuntimeEvents.dispatch.handlerFailureCount += static_cast<uint64_t>(handlerFailures);
|
||||
mRuntimeEvents.dispatch.lastDispatchDurationMilliseconds = std::max(dispatchDurationMilliseconds, 0.0);
|
||||
mRuntimeEvents.dispatch.maxDispatchDurationMilliseconds = std::max(
|
||||
mRuntimeEvents.dispatch.maxDispatchDurationMilliseconds,
|
||||
mRuntimeEvents.dispatch.lastDispatchDurationMilliseconds);
|
||||
return true;
|
||||
}
|
||||
|
||||
HealthTelemetry::SignalStatusSnapshot HealthTelemetry::GetSignalStatusSnapshot() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
@@ -129,6 +187,12 @@ HealthTelemetry::PerformanceSnapshot HealthTelemetry::GetPerformanceSnapshot() c
|
||||
return mPerformance;
|
||||
}
|
||||
|
||||
HealthTelemetry::RuntimeEventMetricsSnapshot HealthTelemetry::GetRuntimeEventMetricsSnapshot() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
return mRuntimeEvents;
|
||||
}
|
||||
|
||||
HealthTelemetry::Snapshot HealthTelemetry::GetSnapshot() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
@@ -137,5 +201,6 @@ HealthTelemetry::Snapshot HealthTelemetry::GetSnapshot() const
|
||||
snapshot.signal = mSignalStatus;
|
||||
snapshot.videoIO = mVideoIOStatus;
|
||||
snapshot.performance = mPerformance;
|
||||
snapshot.runtimeEvents = mRuntimeEvents;
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
@@ -43,11 +44,37 @@ public:
|
||||
uint64_t flushedFrameCount = 0;
|
||||
};
|
||||
|
||||
struct RuntimeEventQueueSnapshot
|
||||
{
|
||||
std::string queueName = "runtime-events";
|
||||
std::size_t depth = 0;
|
||||
std::size_t capacity = 0;
|
||||
uint64_t droppedCount = 0;
|
||||
double oldestEventAgeMilliseconds = 0.0;
|
||||
};
|
||||
|
||||
struct RuntimeEventDispatchSnapshot
|
||||
{
|
||||
uint64_t dispatchCallCount = 0;
|
||||
uint64_t dispatchedEventCount = 0;
|
||||
uint64_t handlerInvocationCount = 0;
|
||||
uint64_t handlerFailureCount = 0;
|
||||
double lastDispatchDurationMilliseconds = 0.0;
|
||||
double maxDispatchDurationMilliseconds = 0.0;
|
||||
};
|
||||
|
||||
struct RuntimeEventMetricsSnapshot
|
||||
{
|
||||
RuntimeEventQueueSnapshot queue;
|
||||
RuntimeEventDispatchSnapshot dispatch;
|
||||
};
|
||||
|
||||
struct Snapshot
|
||||
{
|
||||
SignalStatusSnapshot signal;
|
||||
VideoIOStatusSnapshot videoIO;
|
||||
PerformanceSnapshot performance;
|
||||
RuntimeEventMetricsSnapshot runtimeEvents;
|
||||
};
|
||||
|
||||
HealthTelemetry() = default;
|
||||
@@ -70,9 +97,20 @@ public:
|
||||
bool TryRecordFramePacingStats(double completionIntervalMilliseconds, double smoothedCompletionIntervalMilliseconds,
|
||||
double maxCompletionIntervalMilliseconds, uint64_t lateFrameCount, uint64_t droppedFrameCount, uint64_t flushedFrameCount);
|
||||
|
||||
void RecordRuntimeEventQueueMetrics(const std::string& queueName, std::size_t depth, std::size_t capacity,
|
||||
uint64_t droppedCount, double oldestEventAgeMilliseconds);
|
||||
bool TryRecordRuntimeEventQueueMetrics(const std::string& queueName, std::size_t depth, std::size_t capacity,
|
||||
uint64_t droppedCount, double oldestEventAgeMilliseconds);
|
||||
|
||||
void RecordRuntimeEventDispatchStats(std::size_t dispatchedEvents, std::size_t handlerInvocations,
|
||||
std::size_t handlerFailures, double dispatchDurationMilliseconds);
|
||||
bool TryRecordRuntimeEventDispatchStats(std::size_t dispatchedEvents, std::size_t handlerInvocations,
|
||||
std::size_t handlerFailures, double dispatchDurationMilliseconds);
|
||||
|
||||
SignalStatusSnapshot GetSignalStatusSnapshot() const;
|
||||
VideoIOStatusSnapshot GetVideoIOStatusSnapshot() const;
|
||||
PerformanceSnapshot GetPerformanceSnapshot() const;
|
||||
RuntimeEventMetricsSnapshot GetRuntimeEventMetricsSnapshot() const;
|
||||
Snapshot GetSnapshot() const;
|
||||
|
||||
private:
|
||||
@@ -80,4 +118,5 @@ private:
|
||||
SignalStatusSnapshot mSignalStatus;
|
||||
VideoIOStatusSnapshot mVideoIOStatus;
|
||||
PerformanceSnapshot mPerformance;
|
||||
RuntimeEventMetricsSnapshot mRuntimeEvents;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user