Runtime snapshot provider changes
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "RuntimeSnapshotProvider.h"
|
||||
|
||||
#include "RuntimeClock.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
RuntimeSnapshotProvider::RuntimeSnapshotProvider(RuntimeHost& runtimeHost) :
|
||||
@@ -28,7 +32,7 @@ RuntimeSnapshotVersions RuntimeSnapshotProvider::GetVersions() const
|
||||
RuntimeRenderFrameContext RuntimeSnapshotProvider::GetFrameContext() const
|
||||
{
|
||||
std::vector<RuntimeRenderState> stateScratch(1);
|
||||
mRuntimeHost.RefreshDynamicRenderStateFields(stateScratch);
|
||||
RefreshDynamicRenderStateFields(stateScratch);
|
||||
|
||||
RuntimeRenderFrameContext frameContext;
|
||||
const RuntimeRenderState& state = stateScratch.front();
|
||||
@@ -59,7 +63,7 @@ RuntimeRenderStateSnapshot RuntimeSnapshotProvider::GetRenderStateSnapshot(unsig
|
||||
RuntimeRenderStateSnapshot snapshot;
|
||||
snapshot.outputWidth = outputWidth;
|
||||
snapshot.outputHeight = outputHeight;
|
||||
snapshot.states = mRuntimeHost.GetLayerRenderStates(outputWidth, outputHeight);
|
||||
snapshot.states = GetLayerRenderStates(outputWidth, outputHeight);
|
||||
|
||||
const RuntimeSnapshotVersions versionsAfter = GetVersions();
|
||||
if (versionsBefore.renderStateVersion == versionsAfter.renderStateVersion &&
|
||||
@@ -76,7 +80,7 @@ bool RuntimeSnapshotProvider::TryGetRenderStateSnapshot(unsigned outputWidth, un
|
||||
const RuntimeSnapshotVersions versionsBefore = GetVersions();
|
||||
|
||||
std::vector<RuntimeRenderState> states;
|
||||
if (!mRuntimeHost.TryGetLayerRenderStates(outputWidth, outputHeight, states))
|
||||
if (!TryGetLayerRenderStates(outputWidth, outputHeight, states))
|
||||
return false;
|
||||
|
||||
const RuntimeSnapshotVersions versionsAfter = GetVersions();
|
||||
@@ -96,7 +100,7 @@ bool RuntimeSnapshotProvider::TryGetRenderStateSnapshot(unsigned outputWidth, un
|
||||
bool RuntimeSnapshotProvider::TryRefreshSnapshotParameters(RuntimeRenderStateSnapshot& snapshot) const
|
||||
{
|
||||
const uint64_t expectedRenderStateVersion = snapshot.versions.renderStateVersion;
|
||||
if (!mRuntimeHost.TryRefreshCachedLayerStates(snapshot.states))
|
||||
if (!TryRefreshCachedLayerStates(snapshot.states))
|
||||
return false;
|
||||
|
||||
const RuntimeSnapshotVersions versions = GetVersions();
|
||||
@@ -126,35 +130,37 @@ void RuntimeSnapshotProvider::ApplyFrameContext(RuntimeRenderStateSnapshot& snap
|
||||
|
||||
std::vector<RuntimeRenderState> RuntimeSnapshotProvider::GetLayerRenderStates(unsigned outputWidth, unsigned outputHeight) const
|
||||
{
|
||||
return GetRenderStateSnapshot(outputWidth, outputHeight).states;
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
std::vector<RuntimeRenderState> states;
|
||||
BuildLayerRenderStatesLocked(outputWidth, outputHeight, states);
|
||||
return states;
|
||||
}
|
||||
|
||||
bool RuntimeSnapshotProvider::TryGetLayerRenderStates(unsigned outputWidth, unsigned outputHeight, std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
RuntimeRenderStateSnapshot snapshot;
|
||||
if (!TryGetRenderStateSnapshot(outputWidth, outputHeight, snapshot))
|
||||
std::unique_lock<std::mutex> lock(mRuntimeHost.mMutex, std::try_to_lock);
|
||||
if (!lock.owns_lock())
|
||||
return false;
|
||||
|
||||
states = std::move(snapshot.states);
|
||||
states.clear();
|
||||
BuildLayerRenderStatesLocked(outputWidth, outputHeight, states);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeSnapshotProvider::TryRefreshCachedLayerStates(std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
RuntimeRenderStateSnapshot snapshot;
|
||||
snapshot.versions.renderStateVersion = mRuntimeHost.GetRenderStateVersion();
|
||||
snapshot.versions.parameterStateVersion = mRuntimeHost.GetParameterStateVersion();
|
||||
snapshot.states = states;
|
||||
if (!TryRefreshSnapshotParameters(snapshot))
|
||||
std::unique_lock<std::mutex> lock(mRuntimeHost.mMutex, std::try_to_lock);
|
||||
if (!lock.owns_lock())
|
||||
return false;
|
||||
|
||||
states = std::move(snapshot.states);
|
||||
RefreshCachedLayerStatesLocked(states);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::RefreshDynamicRenderStateFields(std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
ApplyFrameContext(states, GetFrameContext());
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
RefreshDynamicRenderStateFieldsLocked(states);
|
||||
}
|
||||
|
||||
uint64_t RuntimeSnapshotProvider::GetRenderStateVersion() const
|
||||
@@ -166,3 +172,85 @@ uint64_t RuntimeSnapshotProvider::GetParameterStateVersion() const
|
||||
{
|
||||
return GetVersions().parameterStateVersion;
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned outputHeight, std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
const HealthTelemetry::SignalStatusSnapshot signalStatus = mRuntimeHost.mHealthTelemetry.GetSignalStatusSnapshot();
|
||||
|
||||
for (const RuntimeHost::LayerPersistentState& layer : mRuntimeHost.mPersistentState.layers)
|
||||
{
|
||||
auto shaderIt = mRuntimeHost.mPackagesById.find(layer.shaderId);
|
||||
if (shaderIt == mRuntimeHost.mPackagesById.end())
|
||||
continue;
|
||||
|
||||
RuntimeRenderState state;
|
||||
state.layerId = layer.id;
|
||||
state.shaderId = layer.shaderId;
|
||||
state.shaderName = shaderIt->second.displayName;
|
||||
state.mixAmount = 1.0;
|
||||
state.bypass = layer.bypass ? 1.0 : 0.0;
|
||||
state.inputWidth = signalStatus.width;
|
||||
state.inputHeight = signalStatus.height;
|
||||
state.outputWidth = outputWidth;
|
||||
state.outputHeight = outputHeight;
|
||||
state.parameterDefinitions = shaderIt->second.parameters;
|
||||
state.textureAssets = shaderIt->second.textureAssets;
|
||||
state.fontAssets = shaderIt->second.fontAssets;
|
||||
state.isTemporal = shaderIt->second.temporal.enabled;
|
||||
state.temporalHistorySource = shaderIt->second.temporal.historySource;
|
||||
state.requestedTemporalHistoryLength = shaderIt->second.temporal.requestedHistoryLength;
|
||||
state.effectiveTemporalHistoryLength = shaderIt->second.temporal.effectiveHistoryLength;
|
||||
state.feedback = shaderIt->second.feedback;
|
||||
|
||||
for (const ShaderParameterDefinition& definition : shaderIt->second.parameters)
|
||||
{
|
||||
ShaderParameterValue value = mRuntimeHost.DefaultValueForDefinition(definition);
|
||||
auto valueIt = layer.parameterValues.find(definition.id);
|
||||
if (valueIt != layer.parameterValues.end())
|
||||
value = valueIt->second;
|
||||
state.parameterValues[definition.id] = value;
|
||||
}
|
||||
|
||||
states.push_back(state);
|
||||
}
|
||||
|
||||
RefreshDynamicRenderStateFieldsLocked(states);
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::RefreshCachedLayerStatesLocked(std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
for (RuntimeRenderState& state : states)
|
||||
{
|
||||
const auto layerIt = std::find_if(mRuntimeHost.mPersistentState.layers.begin(), mRuntimeHost.mPersistentState.layers.end(),
|
||||
[&state](const RuntimeHost::LayerPersistentState& layer) { return layer.id == state.layerId; });
|
||||
if (layerIt == mRuntimeHost.mPersistentState.layers.end())
|
||||
continue;
|
||||
|
||||
state.bypass = layerIt->bypass ? 1.0 : 0.0;
|
||||
state.parameterValues.clear();
|
||||
for (const ShaderParameterDefinition& definition : state.parameterDefinitions)
|
||||
{
|
||||
ShaderParameterValue value = mRuntimeHost.DefaultValueForDefinition(definition);
|
||||
auto valueIt = layerIt->parameterValues.find(definition.id);
|
||||
if (valueIt != layerIt->parameterValues.end())
|
||||
value = valueIt->second;
|
||||
state.parameterValues[definition.id] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::RefreshDynamicRenderStateFieldsLocked(std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
const RuntimeClockSnapshot clock = GetRuntimeClockSnapshot();
|
||||
const double timeSeconds = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - mRuntimeHost.mStartTime).count();
|
||||
const double frameCount = static_cast<double>(mRuntimeHost.mFrameCounter.load(std::memory_order_relaxed));
|
||||
|
||||
for (RuntimeRenderState& state : states)
|
||||
{
|
||||
state.timeSeconds = timeSeconds;
|
||||
state.utcTimeSeconds = clock.utcTimeSeconds;
|
||||
state.utcOffsetSeconds = clock.utcOffsetSeconds;
|
||||
state.startupRandom = mRuntimeHost.mStartupRandom;
|
||||
state.frameCount = frameCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user