diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/pipeline/OpenGLRenderPipeline.cpp b/apps/LoopThroughWithOpenGLCompositing/gl/pipeline/OpenGLRenderPipeline.cpp index 3eb5061..93b937b 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/pipeline/OpenGLRenderPipeline.cpp +++ b/apps/LoopThroughWithOpenGLCompositing/gl/pipeline/OpenGLRenderPipeline.cpp @@ -51,7 +51,7 @@ bool OpenGLRenderPipeline::RenderFrame(const RenderPipelineFrameContext& context const auto renderEndTime = std::chrono::steady_clock::now(); const double renderMilliseconds = std::chrono::duration_cast>(renderEndTime - renderStartTime).count(); mHealthTelemetry.TryRecordPerformanceStats(state.frameBudgetMilliseconds, renderMilliseconds); - mRuntimeSnapshotProvider.TryAdvanceFrame(); + mRuntimeSnapshotProvider.AdvanceFrame(); ReadOutputFrame(state, outputFrame); if (mPaint) diff --git a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp index 025a916..81b68b5 100644 --- a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp +++ b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp @@ -80,32 +80,11 @@ RuntimeSnapshotVersions RuntimeSnapshotProvider::GetVersions() const return versions; } -RuntimeRenderFrameContext RuntimeSnapshotProvider::GetFrameContext() const -{ - std::vector stateScratch(1); - 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; -} - void RuntimeSnapshotProvider::AdvanceFrame() { ++mRuntimeHost.mFrameCounter; } -bool RuntimeSnapshotProvider::TryAdvanceFrame() -{ - ++mRuntimeHost.mFrameCounter; - return true; -} - RuntimeRenderStateSnapshot RuntimeSnapshotProvider::GetRenderStateSnapshot(unsigned outputWidth, unsigned outputHeight) const { for (;;) @@ -115,7 +94,10 @@ RuntimeRenderStateSnapshot RuntimeSnapshotProvider::GetRenderStateSnapshot(unsig RuntimeRenderStateSnapshot snapshot; snapshot.outputWidth = outputWidth; snapshot.outputHeight = outputHeight; - snapshot.states = GetLayerRenderStates(outputWidth, outputHeight); + { + std::lock_guard lock(mRuntimeHost.mMutex); + BuildLayerRenderStatesLocked(outputWidth, outputHeight, snapshot.states); + } const RuntimeSnapshotVersions versionsAfter = GetVersions(); if (versionsBefore.renderStateVersion == versionsAfter.renderStateVersion && @@ -132,8 +114,13 @@ bool RuntimeSnapshotProvider::TryGetRenderStateSnapshot(unsigned outputWidth, un const RuntimeSnapshotVersions versionsBefore = GetVersions(); std::vector states; - if (!TryGetLayerRenderStates(outputWidth, outputHeight, states)) - return false; + { + std::unique_lock lock(mRuntimeHost.mMutex, std::try_to_lock); + if (!lock.owns_lock()) + return false; + + BuildLayerRenderStatesLocked(outputWidth, outputHeight, states); + } const RuntimeSnapshotVersions versionsAfter = GetVersions(); if (versionsBefore.renderStateVersion != versionsAfter.renderStateVersion || @@ -152,8 +139,13 @@ bool RuntimeSnapshotProvider::TryGetRenderStateSnapshot(unsigned outputWidth, un bool RuntimeSnapshotProvider::TryRefreshSnapshotParameters(RuntimeRenderStateSnapshot& snapshot) const { const uint64_t expectedRenderStateVersion = snapshot.versions.renderStateVersion; - if (!TryRefreshCachedLayerStates(snapshot.states)) - return false; + { + std::unique_lock lock(mRuntimeHost.mMutex, std::try_to_lock); + if (!lock.owns_lock()) + return false; + + RefreshCachedLayerStatesLocked(snapshot.states); + } const RuntimeSnapshotVersions versions = GetVersions(); if (versions.renderStateVersion != expectedRenderStateVersion) @@ -163,68 +155,12 @@ bool RuntimeSnapshotProvider::TryRefreshSnapshotParameters(RuntimeRenderStateSna return true; } -void RuntimeSnapshotProvider::ApplyFrameContext(std::vector& 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 RuntimeSnapshotProvider::GetLayerRenderStates(unsigned outputWidth, unsigned outputHeight) const -{ - std::lock_guard lock(mRuntimeHost.mMutex); - std::vector states; - BuildLayerRenderStatesLocked(outputWidth, outputHeight, states); - return states; -} - -bool RuntimeSnapshotProvider::TryGetLayerRenderStates(unsigned outputWidth, unsigned outputHeight, std::vector& states) const -{ - std::unique_lock lock(mRuntimeHost.mMutex, std::try_to_lock); - if (!lock.owns_lock()) - return false; - - states.clear(); - BuildLayerRenderStatesLocked(outputWidth, outputHeight, states); - return true; -} - -bool RuntimeSnapshotProvider::TryRefreshCachedLayerStates(std::vector& states) const -{ - std::unique_lock lock(mRuntimeHost.mMutex, std::try_to_lock); - if (!lock.owns_lock()) - return false; - - RefreshCachedLayerStatesLocked(states); - return true; -} - void RuntimeSnapshotProvider::RefreshDynamicRenderStateFields(std::vector& states) const { std::lock_guard lock(mRuntimeHost.mMutex); RefreshDynamicRenderStateFieldsLocked(states); } -uint64_t RuntimeSnapshotProvider::GetRenderStateVersion() const -{ - return GetVersions().renderStateVersion; -} - -uint64_t RuntimeSnapshotProvider::GetParameterStateVersion() const -{ - return GetVersions().parameterStateVersion; -} - void RuntimeSnapshotProvider::BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned outputHeight, std::vector& states) const { const HealthTelemetry::SignalStatusSnapshot signalStatus = mRuntimeHost.mHealthTelemetry.GetSignalStatusSnapshot(); diff --git a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h index b6cb7c2..2ae5c02 100644 --- a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h +++ b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h @@ -12,15 +12,6 @@ struct RuntimeSnapshotVersions uint64_t parameterStateVersion = 0; }; -struct RuntimeRenderFrameContext -{ - double timeSeconds = 0.0; - double utcTimeSeconds = 0.0; - double utcOffsetSeconds = 0.0; - double startupRandom = 0.0; - double frameCount = 0.0; -}; - struct RuntimeRenderStateSnapshot { RuntimeSnapshotVersions versions; @@ -37,21 +28,11 @@ public: bool BuildLayerPassFragmentShaderSources(const std::string& layerId, std::vector& passSources, std::string& error) const; unsigned GetMaxTemporalHistoryFrames() const; RuntimeSnapshotVersions GetVersions() const; - RuntimeRenderFrameContext GetFrameContext() const; void AdvanceFrame(); - bool TryAdvanceFrame(); RuntimeRenderStateSnapshot GetRenderStateSnapshot(unsigned outputWidth, unsigned outputHeight) const; bool TryGetRenderStateSnapshot(unsigned outputWidth, unsigned outputHeight, RuntimeRenderStateSnapshot& snapshot) const; bool TryRefreshSnapshotParameters(RuntimeRenderStateSnapshot& snapshot) const; - void ApplyFrameContext(std::vector& states, const RuntimeRenderFrameContext& frameContext) const; - void ApplyFrameContext(RuntimeRenderStateSnapshot& snapshot, const RuntimeRenderFrameContext& frameContext) const; - - std::vector GetLayerRenderStates(unsigned outputWidth, unsigned outputHeight) const; - bool TryGetLayerRenderStates(unsigned outputWidth, unsigned outputHeight, std::vector& states) const; - bool TryRefreshCachedLayerStates(std::vector& states) const; void RefreshDynamicRenderStateFields(std::vector& states) const; - uint64_t GetRenderStateVersion() const; - uint64_t GetParameterStateVersion() const; private: void BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned outputHeight, std::vector& states) const;