Phase 1 clean-up and separation of concerns
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "RuntimeSnapshotProvider.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
RuntimeSnapshotProvider::RuntimeSnapshotProvider(RuntimeHost& runtimeHost) :
|
||||
mRuntimeHost(runtimeHost)
|
||||
{
|
||||
@@ -10,32 +12,142 @@ bool RuntimeSnapshotProvider::BuildLayerPassFragmentShaderSources(const std::str
|
||||
return mRuntimeHost.BuildLayerPassFragmentShaderSources(layerId, passSources, error);
|
||||
}
|
||||
|
||||
RuntimeSnapshotVersions RuntimeSnapshotProvider::GetVersions() const
|
||||
{
|
||||
RuntimeSnapshotVersions versions;
|
||||
versions.renderStateVersion = mRuntimeHost.GetRenderStateVersion();
|
||||
versions.parameterStateVersion = mRuntimeHost.GetParameterStateVersion();
|
||||
return versions;
|
||||
}
|
||||
|
||||
RuntimeRenderFrameContext RuntimeSnapshotProvider::GetFrameContext() const
|
||||
{
|
||||
std::vector<RuntimeRenderState> stateScratch(1);
|
||||
mRuntimeHost.RefreshDynamicRenderStateFields(stateScratch);
|
||||
|
||||
RuntimeRenderFrameContext frameContext;
|
||||
const RuntimeRenderState& state = stateScratch.front();
|
||||
frameContext.timeSeconds = state.timeSeconds;
|
||||
frameContext.utcTimeSeconds = state.utcTimeSeconds;
|
||||
frameContext.utcOffsetSeconds = state.utcOffsetSeconds;
|
||||
frameContext.startupRandom = state.startupRandom;
|
||||
frameContext.frameCount = state.frameCount;
|
||||
return frameContext;
|
||||
}
|
||||
|
||||
RuntimeRenderStateSnapshot RuntimeSnapshotProvider::GetRenderStateSnapshot(unsigned outputWidth, unsigned outputHeight) const
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
const RuntimeSnapshotVersions versionsBefore = GetVersions();
|
||||
|
||||
RuntimeRenderStateSnapshot snapshot;
|
||||
snapshot.outputWidth = outputWidth;
|
||||
snapshot.outputHeight = outputHeight;
|
||||
snapshot.states = mRuntimeHost.GetLayerRenderStates(outputWidth, outputHeight);
|
||||
|
||||
const RuntimeSnapshotVersions versionsAfter = GetVersions();
|
||||
if (versionsBefore.renderStateVersion == versionsAfter.renderStateVersion &&
|
||||
versionsBefore.parameterStateVersion == versionsAfter.parameterStateVersion)
|
||||
{
|
||||
snapshot.versions = versionsAfter;
|
||||
return snapshot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RuntimeSnapshotProvider::TryGetRenderStateSnapshot(unsigned outputWidth, unsigned outputHeight, RuntimeRenderStateSnapshot& snapshot) const
|
||||
{
|
||||
const RuntimeSnapshotVersions versionsBefore = GetVersions();
|
||||
|
||||
std::vector<RuntimeRenderState> states;
|
||||
if (!mRuntimeHost.TryGetLayerRenderStates(outputWidth, outputHeight, states))
|
||||
return false;
|
||||
|
||||
const RuntimeSnapshotVersions versionsAfter = GetVersions();
|
||||
if (versionsBefore.renderStateVersion != versionsAfter.renderStateVersion ||
|
||||
versionsBefore.parameterStateVersion != versionsAfter.parameterStateVersion)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
snapshot.outputWidth = outputWidth;
|
||||
snapshot.outputHeight = outputHeight;
|
||||
snapshot.versions = versionsAfter;
|
||||
snapshot.states = std::move(states);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeSnapshotProvider::TryRefreshSnapshotParameters(RuntimeRenderStateSnapshot& snapshot) const
|
||||
{
|
||||
const uint64_t expectedRenderStateVersion = snapshot.versions.renderStateVersion;
|
||||
if (!mRuntimeHost.TryRefreshCachedLayerStates(snapshot.states))
|
||||
return false;
|
||||
|
||||
const RuntimeSnapshotVersions versions = GetVersions();
|
||||
if (versions.renderStateVersion != expectedRenderStateVersion)
|
||||
return false;
|
||||
|
||||
snapshot.versions = versions;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::ApplyFrameContext(std::vector<RuntimeRenderState>& states, const RuntimeRenderFrameContext& frameContext) const
|
||||
{
|
||||
for (RuntimeRenderState& state : states)
|
||||
{
|
||||
state.timeSeconds = frameContext.timeSeconds;
|
||||
state.utcTimeSeconds = frameContext.utcTimeSeconds;
|
||||
state.utcOffsetSeconds = frameContext.utcOffsetSeconds;
|
||||
state.startupRandom = frameContext.startupRandom;
|
||||
state.frameCount = frameContext.frameCount;
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::ApplyFrameContext(RuntimeRenderStateSnapshot& snapshot, const RuntimeRenderFrameContext& frameContext) const
|
||||
{
|
||||
ApplyFrameContext(snapshot.states, frameContext);
|
||||
}
|
||||
|
||||
std::vector<RuntimeRenderState> RuntimeSnapshotProvider::GetLayerRenderStates(unsigned outputWidth, unsigned outputHeight) const
|
||||
{
|
||||
return mRuntimeHost.GetLayerRenderStates(outputWidth, outputHeight);
|
||||
return GetRenderStateSnapshot(outputWidth, outputHeight).states;
|
||||
}
|
||||
|
||||
bool RuntimeSnapshotProvider::TryGetLayerRenderStates(unsigned outputWidth, unsigned outputHeight, std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
return mRuntimeHost.TryGetLayerRenderStates(outputWidth, outputHeight, states);
|
||||
RuntimeRenderStateSnapshot snapshot;
|
||||
if (!TryGetRenderStateSnapshot(outputWidth, outputHeight, snapshot))
|
||||
return false;
|
||||
|
||||
states = std::move(snapshot.states);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuntimeSnapshotProvider::TryRefreshCachedLayerStates(std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
return mRuntimeHost.TryRefreshCachedLayerStates(states);
|
||||
RuntimeRenderStateSnapshot snapshot;
|
||||
snapshot.versions.renderStateVersion = mRuntimeHost.GetRenderStateVersion();
|
||||
snapshot.versions.parameterStateVersion = mRuntimeHost.GetParameterStateVersion();
|
||||
snapshot.states = states;
|
||||
if (!TryRefreshSnapshotParameters(snapshot))
|
||||
return false;
|
||||
|
||||
states = std::move(snapshot.states);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RuntimeSnapshotProvider::RefreshDynamicRenderStateFields(std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
mRuntimeHost.RefreshDynamicRenderStateFields(states);
|
||||
ApplyFrameContext(states, GetFrameContext());
|
||||
}
|
||||
|
||||
uint64_t RuntimeSnapshotProvider::GetRenderStateVersion() const
|
||||
{
|
||||
return mRuntimeHost.GetRenderStateVersion();
|
||||
return GetVersions().renderStateVersion;
|
||||
}
|
||||
|
||||
uint64_t RuntimeSnapshotProvider::GetParameterStateVersion() const
|
||||
{
|
||||
return mRuntimeHost.GetParameterStateVersion();
|
||||
return GetVersions().parameterStateVersion;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user