Phase 3 refactor in progress
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#include "RuntimeServiceLiveBridge.h"
|
||||
|
||||
#include "RuntimeServices.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
void RuntimeServiceLiveBridge::DrainServiceEvents(RuntimeServices& runtimeServices, RenderEngine& renderEngine)
|
||||
{
|
||||
std::vector<RuntimeServices::AppliedOscUpdate> appliedOscUpdates;
|
||||
std::vector<RuntimeServices::CompletedOscCommit> completedOscCommits;
|
||||
|
||||
std::string oscError;
|
||||
if (!runtimeServices.ApplyPendingOscUpdates(appliedOscUpdates, oscError) && !oscError.empty())
|
||||
OutputDebugStringA(("OSC apply failed: " + oscError + "\n").c_str());
|
||||
runtimeServices.ConsumeCompletedOscCommits(completedOscCommits);
|
||||
|
||||
std::vector<RenderEngine::OscOverlayUpdate> overlayUpdates;
|
||||
overlayUpdates.reserve(appliedOscUpdates.size());
|
||||
for (const RuntimeServices::AppliedOscUpdate& update : appliedOscUpdates)
|
||||
{
|
||||
overlayUpdates.push_back({ update.routeKey, update.layerKey, update.parameterKey, update.targetValue });
|
||||
}
|
||||
|
||||
std::vector<RenderEngine::OscOverlayCommitCompletion> overlayCommitCompletions;
|
||||
overlayCommitCompletions.reserve(completedOscCommits.size());
|
||||
for (const RuntimeServices::CompletedOscCommit& completedCommit : completedOscCommits)
|
||||
{
|
||||
overlayCommitCompletions.push_back({ completedCommit.routeKey, completedCommit.generation });
|
||||
}
|
||||
|
||||
renderEngine.UpdateOscOverlayState(overlayUpdates, overlayCommitCompletions);
|
||||
}
|
||||
|
||||
void RuntimeServiceLiveBridge::QueueServiceCommitRequests(
|
||||
RuntimeServices& runtimeServices,
|
||||
const std::vector<RenderEngine::OscOverlayCommitRequest>& commitRequests)
|
||||
{
|
||||
for (const RenderEngine::OscOverlayCommitRequest& commitRequest : commitRequests)
|
||||
{
|
||||
std::string commitError;
|
||||
if (!runtimeServices.QueueOscCommit(
|
||||
commitRequest.routeKey,
|
||||
commitRequest.layerKey,
|
||||
commitRequest.parameterKey,
|
||||
commitRequest.value,
|
||||
commitRequest.generation,
|
||||
commitError) &&
|
||||
!commitError.empty())
|
||||
{
|
||||
OutputDebugStringA(("OSC commit queue failed: " + commitError + "\n").c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RuntimeServiceLiveBridge::PrepareLiveRenderLayerStates(
|
||||
RuntimeServices& runtimeServices,
|
||||
RenderEngine& renderEngine,
|
||||
bool useCommittedLayerStates,
|
||||
unsigned renderWidth,
|
||||
unsigned renderHeight,
|
||||
double oscSmoothing,
|
||||
std::vector<RuntimeRenderState>& layerStates)
|
||||
{
|
||||
DrainServiceEvents(runtimeServices, renderEngine);
|
||||
|
||||
std::vector<RenderEngine::OscOverlayCommitRequest> commitRequests;
|
||||
const bool resolved = renderEngine.ResolveRenderLayerStates(
|
||||
useCommittedLayerStates,
|
||||
renderWidth,
|
||||
renderHeight,
|
||||
oscSmoothing,
|
||||
&commitRequests,
|
||||
layerStates);
|
||||
|
||||
QueueServiceCommitRequests(runtimeServices, commitRequests);
|
||||
return resolved;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderEngine.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RuntimeServices;
|
||||
|
||||
class RuntimeServiceLiveBridge
|
||||
{
|
||||
public:
|
||||
static void DrainServiceEvents(RuntimeServices& runtimeServices, RenderEngine& renderEngine);
|
||||
static void QueueServiceCommitRequests(
|
||||
RuntimeServices& runtimeServices,
|
||||
const std::vector<RenderEngine::OscOverlayCommitRequest>& commitRequests);
|
||||
static bool PrepareLiveRenderLayerStates(
|
||||
RuntimeServices& runtimeServices,
|
||||
RenderEngine& renderEngine,
|
||||
bool useCommittedLayerStates,
|
||||
unsigned renderWidth,
|
||||
unsigned renderHeight,
|
||||
double oscSmoothing,
|
||||
std::vector<RuntimeRenderState>& layerStates);
|
||||
};
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "RuntimeCoordinator.h"
|
||||
#include "RuntimeEventDispatcher.h"
|
||||
#include "RuntimeParameterUtils.h"
|
||||
#include "RuntimeServiceLiveBridge.h"
|
||||
#include "RuntimeServices.h"
|
||||
#include "RuntimeSnapshotProvider.h"
|
||||
#include "RuntimeStore.h"
|
||||
@@ -302,61 +303,30 @@ void OpenGLComposite::renderEffect()
|
||||
{
|
||||
if (mRuntimeUpdateController)
|
||||
mRuntimeUpdateController->ProcessRuntimeWork();
|
||||
std::vector<RuntimeServices::AppliedOscUpdate> appliedOscUpdates;
|
||||
std::vector<RuntimeServices::CompletedOscCommit> completedOscCommits;
|
||||
if (mRuntimeServices)
|
||||
{
|
||||
std::string oscError;
|
||||
if (!mRuntimeServices->ApplyPendingOscUpdates(appliedOscUpdates, oscError) && !oscError.empty())
|
||||
OutputDebugStringA(("OSC apply failed: " + oscError + "\n").c_str());
|
||||
mRuntimeServices->ConsumeCompletedOscCommits(completedOscCommits);
|
||||
}
|
||||
|
||||
std::vector<RenderEngine::OscOverlayUpdate> overlayUpdates;
|
||||
overlayUpdates.reserve(appliedOscUpdates.size());
|
||||
for (const RuntimeServices::AppliedOscUpdate& update : appliedOscUpdates)
|
||||
{
|
||||
overlayUpdates.push_back({ update.routeKey, update.layerKey, update.parameterKey, update.targetValue });
|
||||
}
|
||||
|
||||
std::vector<RenderEngine::OscOverlayCommitCompletion> overlayCommitCompletions;
|
||||
overlayCommitCompletions.reserve(completedOscCommits.size());
|
||||
for (const RuntimeServices::CompletedOscCommit& completedCommit : completedOscCommits)
|
||||
{
|
||||
overlayCommitCompletions.push_back({ completedCommit.routeKey, completedCommit.generation });
|
||||
}
|
||||
|
||||
if (mRenderEngine)
|
||||
mRenderEngine->UpdateOscOverlayState(overlayUpdates, overlayCommitCompletions);
|
||||
|
||||
const bool hasInputSource = mVideoBackend->HasInputSource();
|
||||
std::vector<RuntimeRenderState> layerStates;
|
||||
std::vector<RenderEngine::OscOverlayCommitRequest> overlayCommitRequests;
|
||||
const double smoothing = mRuntimeStore ? mRuntimeStore->GetConfiguredOscSmoothing() : 0.0;
|
||||
mRenderEngine->ResolveRenderLayerStates(
|
||||
mRuntimeCoordinator && mRuntimeCoordinator->UseCommittedLayerStates(),
|
||||
mVideoBackend->InputFrameWidth(),
|
||||
mVideoBackend->InputFrameHeight(),
|
||||
smoothing,
|
||||
&overlayCommitRequests,
|
||||
layerStates);
|
||||
if (mRuntimeServices)
|
||||
{
|
||||
for (const RenderEngine::OscOverlayCommitRequest& commitRequest : overlayCommitRequests)
|
||||
{
|
||||
std::string commitError;
|
||||
if (!mRuntimeServices->QueueOscCommit(
|
||||
commitRequest.routeKey,
|
||||
commitRequest.layerKey,
|
||||
commitRequest.parameterKey,
|
||||
commitRequest.value,
|
||||
commitRequest.generation,
|
||||
commitError) &&
|
||||
!commitError.empty())
|
||||
{
|
||||
OutputDebugStringA(("OSC commit queue failed: " + commitError + "\n").c_str());
|
||||
}
|
||||
}
|
||||
RuntimeServiceLiveBridge::PrepareLiveRenderLayerStates(
|
||||
*mRuntimeServices,
|
||||
*mRenderEngine,
|
||||
mRuntimeCoordinator && mRuntimeCoordinator->UseCommittedLayerStates(),
|
||||
mVideoBackend->InputFrameWidth(),
|
||||
mVideoBackend->InputFrameHeight(),
|
||||
smoothing,
|
||||
layerStates);
|
||||
}
|
||||
else
|
||||
{
|
||||
mRenderEngine->ResolveRenderLayerStates(
|
||||
mRuntimeCoordinator && mRuntimeCoordinator->UseCommittedLayerStates(),
|
||||
mVideoBackend->InputFrameWidth(),
|
||||
mVideoBackend->InputFrameHeight(),
|
||||
smoothing,
|
||||
nullptr,
|
||||
layerStates);
|
||||
}
|
||||
const unsigned historyCap = mRuntimeStore ? mRuntimeStore->GetConfiguredMaxTemporalHistoryFrames() : 0;
|
||||
mRenderEngine->RenderLayerStack(
|
||||
|
||||
@@ -259,8 +259,7 @@ bool RenderEngine::ResolveRenderLayerStates(
|
||||
layerStates.clear();
|
||||
if (useCommittedLayerStates)
|
||||
{
|
||||
layerStates = mShaderPrograms.CommittedLayerStates();
|
||||
ApplyOscOverlays(layerStates, false, oscSmoothing, commitRequests);
|
||||
layerStates = ComposeRenderLayerStates(mShaderPrograms.CommittedLayerStates(), false, oscSmoothing, commitRequests);
|
||||
mRuntimeSnapshotProvider.RefreshDynamicRenderStateFields(layerStates);
|
||||
return true;
|
||||
}
|
||||
@@ -281,12 +280,12 @@ bool RenderEngine::ResolveRenderLayerStates(
|
||||
renderSnapshot.versions.parameterStateVersion = mCachedParameterStateVersion;
|
||||
renderSnapshot.states = mCachedLayerRenderStates;
|
||||
|
||||
ApplyOscOverlays(renderSnapshot.states, true, oscSmoothing, commitRequests);
|
||||
renderSnapshot.states = ComposeRenderLayerStates(renderSnapshot.states, true, oscSmoothing, commitRequests);
|
||||
if (mCachedParameterStateVersion != versions.parameterStateVersion &&
|
||||
mRuntimeSnapshotProvider.TryRefreshPublishedSnapshotParameters(renderSnapshot))
|
||||
{
|
||||
mCachedParameterStateVersion = renderSnapshot.versions.parameterStateVersion;
|
||||
ApplyOscOverlays(renderSnapshot.states, true, oscSmoothing, commitRequests);
|
||||
renderSnapshot.states = ComposeRenderLayerStates(renderSnapshot.states, true, oscSmoothing, commitRequests);
|
||||
}
|
||||
|
||||
mCachedLayerRenderStates = renderSnapshot.states;
|
||||
@@ -303,36 +302,38 @@ bool RenderEngine::ResolveRenderLayerStates(
|
||||
mCachedParameterStateVersion = renderSnapshot.versions.parameterStateVersion;
|
||||
mCachedRenderStateWidth = renderSnapshot.outputWidth;
|
||||
mCachedRenderStateHeight = renderSnapshot.outputHeight;
|
||||
ApplyOscOverlays(mCachedLayerRenderStates, true, oscSmoothing, commitRequests);
|
||||
mCachedLayerRenderStates = ComposeRenderLayerStates(mCachedLayerRenderStates, true, oscSmoothing, commitRequests);
|
||||
layerStates = mCachedLayerRenderStates;
|
||||
return true;
|
||||
}
|
||||
|
||||
ApplyOscOverlays(mCachedLayerRenderStates, true, oscSmoothing, commitRequests);
|
||||
layerStates = mCachedLayerRenderStates;
|
||||
layerStates = ComposeRenderLayerStates(mCachedLayerRenderStates, true, oscSmoothing, commitRequests);
|
||||
mRuntimeSnapshotProvider.RefreshDynamicRenderStateFields(layerStates);
|
||||
return !layerStates.empty();
|
||||
}
|
||||
|
||||
void RenderEngine::ApplyOscOverlays(
|
||||
std::vector<RuntimeRenderState>& states,
|
||||
std::vector<RuntimeRenderState> RenderEngine::ComposeRenderLayerStates(
|
||||
const std::vector<RuntimeRenderState>& baseStates,
|
||||
bool allowCommit,
|
||||
double smoothing,
|
||||
std::vector<OscOverlayCommitRequest>* commitRequests)
|
||||
{
|
||||
std::vector<RuntimeLiveOscCommitRequest> liveCommitRequests;
|
||||
RuntimeLiveStateApplyOptions options;
|
||||
options.allowCommit = allowCommit;
|
||||
options.smoothing = smoothing;
|
||||
options.commitDelay = kOscOverlayCommitDelay;
|
||||
options.now = std::chrono::steady_clock::now();
|
||||
mRuntimeLiveState.ApplyToLayerStates(states, options, commitRequests ? &liveCommitRequests : nullptr);
|
||||
RenderStateCompositionInput input;
|
||||
input.baseLayerStates = &baseStates;
|
||||
input.liveState = &mRuntimeLiveState;
|
||||
input.allowLiveCommits = allowCommit;
|
||||
input.collectLiveCommitRequests = commitRequests != nullptr;
|
||||
input.liveSmoothing = smoothing;
|
||||
input.liveCommitDelay = kOscOverlayCommitDelay;
|
||||
input.now = std::chrono::steady_clock::now();
|
||||
const RenderStateCompositionResult result = mRenderStateComposer.BuildFrameState(input);
|
||||
|
||||
if (!commitRequests)
|
||||
return;
|
||||
return result.layerStates;
|
||||
|
||||
for (const RuntimeLiveOscCommitRequest& request : liveCommitRequests)
|
||||
for (const RuntimeLiveOscCommitRequest& request : result.commitRequests)
|
||||
commitRequests->push_back({ request.routeKey, request.layerKey, request.parameterKey, request.value, request.generation });
|
||||
return result.layerStates;
|
||||
}
|
||||
|
||||
void RenderEngine::RenderLayerStack(
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include "OpenGLRenderPipeline.h"
|
||||
#include "OpenGLRenderer.h"
|
||||
#include "OpenGLShaderPrograms.h"
|
||||
#include "RenderStateComposer.h"
|
||||
#include "HealthTelemetry.h"
|
||||
#include "RuntimeCoordinator.h"
|
||||
#include "RuntimeLiveState.h"
|
||||
#include "RuntimeSnapshotProvider.h"
|
||||
|
||||
#include <windows.h>
|
||||
@@ -133,8 +133,8 @@ private:
|
||||
HDC mHdc;
|
||||
HGLRC mHglrc;
|
||||
|
||||
void ApplyOscOverlays(
|
||||
std::vector<RuntimeRenderState>& states,
|
||||
std::vector<RuntimeRenderState> ComposeRenderLayerStates(
|
||||
const std::vector<RuntimeRenderState>& baseStates,
|
||||
bool allowCommit,
|
||||
double smoothing,
|
||||
std::vector<OscOverlayCommitRequest>* commitRequests);
|
||||
@@ -145,5 +145,6 @@ private:
|
||||
unsigned mCachedRenderStateWidth = 0;
|
||||
unsigned mCachedRenderStateHeight = 0;
|
||||
std::chrono::steady_clock::time_point mLastPreviewPresentTime;
|
||||
RenderStateComposer mRenderStateComposer;
|
||||
RuntimeLiveState mRuntimeLiveState;
|
||||
};
|
||||
|
||||
@@ -175,7 +175,7 @@ RuntimeCoordinatorResult RuntimeCoordinator::CommitOscParameterByControlKey(cons
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::string error;
|
||||
ResolvedParameterMutation mutation;
|
||||
if (!BuildParameterMutationByControlKey(layerKey, parameterKey, newValue, false, mutation, error))
|
||||
if (!BuildParameterMutationByControlKey(layerKey, parameterKey, newValue, true, mutation, error))
|
||||
{
|
||||
RuntimeCoordinatorResult result = ApplyStoreMutation(false, error, false, false, false);
|
||||
PublishCoordinatorResult("CommitOscParameterByControlKey", result);
|
||||
|
||||
@@ -3,8 +3,22 @@
|
||||
RenderStateCompositionResult RenderStateComposer::BuildFrameState(const RenderStateCompositionInput& input) const
|
||||
{
|
||||
RenderStateCompositionResult result;
|
||||
result.layerStates = input.baseLayerStates;
|
||||
if (!input.baseLayerStates)
|
||||
return result;
|
||||
|
||||
result.layerStates = *input.baseLayerStates;
|
||||
result.hasLayerStates = !result.layerStates.empty();
|
||||
if (input.liveState)
|
||||
input.liveState->ApplyToLayerStates(result.layerStates, input.liveStateOptions, &result.commitRequests);
|
||||
{
|
||||
RuntimeLiveStateApplyOptions options;
|
||||
options.allowCommit = input.allowLiveCommits;
|
||||
options.smoothing = input.liveSmoothing;
|
||||
options.commitDelay = input.liveCommitDelay;
|
||||
options.now = input.now;
|
||||
input.liveState->ApplyToLayerStates(
|
||||
result.layerStates,
|
||||
options,
|
||||
input.collectLiveCommitRequests ? &result.commitRequests : nullptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,19 +2,25 @@
|
||||
|
||||
#include "RuntimeLiveState.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
struct RenderStateCompositionInput
|
||||
{
|
||||
std::vector<RuntimeRenderState> baseLayerStates;
|
||||
const std::vector<RuntimeRenderState>* baseLayerStates = nullptr;
|
||||
RuntimeLiveState* liveState = nullptr;
|
||||
RuntimeLiveStateApplyOptions liveStateOptions;
|
||||
bool allowLiveCommits = false;
|
||||
bool collectLiveCommitRequests = true;
|
||||
double liveSmoothing = 0.0;
|
||||
std::chrono::milliseconds liveCommitDelay = std::chrono::milliseconds(150);
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
};
|
||||
|
||||
struct RenderStateCompositionResult
|
||||
{
|
||||
std::vector<RuntimeRenderState> layerStates;
|
||||
std::vector<RuntimeLiveOscCommitRequest> commitRequests;
|
||||
bool hasLayerStates = false;
|
||||
};
|
||||
|
||||
class RenderStateComposer
|
||||
|
||||
Reference in New Issue
Block a user