From 3629227aa9c0214723cb240709694dda0dba84f0 Mon Sep 17 00:00:00 2001 From: Aiden <68633820+awils27@users.noreply.github.com> Date: Sun, 10 May 2026 23:03:15 +1000 Subject: [PATCH] intial phase 1 subsytem split --- CMakeLists.txt | 4 + .../gl/OpenGLComposite.cpp | 68 ++++---- .../gl/OpenGLComposite.h | 4 + .../gl/OpenGLCompositeRuntimeControls.cpp | 30 ++-- .../gl/shader/OpenGLShaderPrograms.cpp | 5 +- .../gl/shader/OpenGLShaderPrograms.h | 4 +- .../gl/shader/ShaderBuildQueue.cpp | 10 +- .../gl/shader/ShaderBuildQueue.h | 7 +- .../runtime/RuntimeSnapshotProvider.cpp | 41 +++++ .../runtime/RuntimeSnapshotProvider.h | 24 +++ .../runtime/RuntimeStore.cpp | 161 ++++++++++++++++++ .../runtime/RuntimeStore.h | 51 ++++++ 12 files changed, 348 insertions(+), 61 deletions(-) create mode 100644 apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp create mode 100644 apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h create mode 100644 apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.cpp create mode 100644 apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 98516ac..d12938a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,12 +98,16 @@ set(APP_SOURCES "${APP_DIR}/resource.h" "${APP_DIR}/runtime/RuntimeHost.cpp" "${APP_DIR}/runtime/RuntimeHost.h" + "${APP_DIR}/runtime/RuntimeSnapshotProvider.cpp" + "${APP_DIR}/runtime/RuntimeSnapshotProvider.h" "${APP_DIR}/runtime/RuntimeClock.cpp" "${APP_DIR}/runtime/RuntimeClock.h" "${APP_DIR}/runtime/RuntimeJson.cpp" "${APP_DIR}/runtime/RuntimeJson.h" "${APP_DIR}/runtime/RuntimeParameterUtils.cpp" "${APP_DIR}/runtime/RuntimeParameterUtils.h" + "${APP_DIR}/runtime/RuntimeStore.cpp" + "${APP_DIR}/runtime/RuntimeStore.h" "${APP_DIR}/shader/ShaderCompiler.cpp" "${APP_DIR}/shader/ShaderCompiler.h" "${APP_DIR}/shader/ShaderPackageRegistry.cpp" diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.cpp b/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.cpp index f877a78..1affdbc 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.cpp +++ b/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.cpp @@ -104,6 +104,8 @@ OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) : { InitializeCriticalSection(&pMutex); mRuntimeHost = std::make_unique(); + mRuntimeStore = std::make_unique(*mRuntimeHost); + mRuntimeSnapshotProvider = std::make_unique(*mRuntimeHost); mRenderPipeline = std::make_unique( *mRenderer, *mRuntimeHost, @@ -119,8 +121,8 @@ OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) : hGLDC, hGLRC); mRenderPass = std::make_unique(*mRenderer); - mShaderPrograms = std::make_unique(*mRenderer, *mRuntimeHost); - mShaderBuildQueue = std::make_unique(*mRuntimeHost); + mShaderPrograms = std::make_unique(*mRenderer, *mRuntimeHost, *mRuntimeSnapshotProvider); + mShaderBuildQueue = std::make_unique(*mRuntimeSnapshotProvider); mRuntimeServices = std::make_unique(); } @@ -146,23 +148,23 @@ bool OpenGLComposite::InitVideoIO() VideoFormatSelection videoModes; std::string initFailureReason; - if (mRuntimeHost && mRuntimeHost->GetRepoRoot().empty()) + if (mRuntimeStore && mRuntimeStore->GetRepoRoot().empty()) { std::string runtimeError; - if (!mRuntimeHost->Initialize(runtimeError)) + if (!mRuntimeStore->Initialize(runtimeError)) { MessageBoxA(NULL, runtimeError.c_str(), "Runtime host failed to initialize", MB_OK); return false; } } - if (mRuntimeHost) + if (mRuntimeStore) { if (!ResolveConfiguredVideoFormats( - mRuntimeHost->GetInputVideoFormat(), - mRuntimeHost->GetInputFrameRate(), - mRuntimeHost->GetOutputVideoFormat(), - mRuntimeHost->GetOutputFrameRate(), + mRuntimeStore->GetInputVideoFormat(), + mRuntimeStore->GetInputFrameRate(), + mRuntimeStore->GetOutputVideoFormat(), + mRuntimeStore->GetOutputFrameRate(), videoModes, initFailureReason)) { @@ -179,7 +181,7 @@ bool OpenGLComposite::InitVideoIO() MessageBoxA(NULL, initFailureReason.c_str(), title, MB_OK | MB_ICONERROR); return false; } - const bool outputAlphaRequired = mRuntimeHost && mRuntimeHost->ExternalKeyingEnabled(); + const bool outputAlphaRequired = mRuntimeStore && mRuntimeStore->ExternalKeyingEnabled(); if (!mVideoIO->SelectPreferredFormats(videoModes, outputAlphaRequired, initFailureReason)) goto error; @@ -214,7 +216,7 @@ bool OpenGLComposite::InitVideoIO() mRuntimeHost->SetSignalStatus(false, mVideoIO->InputFrameWidth(), mVideoIO->InputFrameHeight(), mVideoIO->InputDisplayModeName()); } - if (!mVideoIO->ConfigureOutput([this](const VideoIOCompletion& completion) { mVideoIOBridge->PlayoutFrameCompleted(completion); }, videoModes.output, mRuntimeHost && mRuntimeHost->ExternalKeyingEnabled(), initFailureReason)) + if (!mVideoIO->ConfigureOutput([this](const VideoIOCompletion& completion) { mVideoIOBridge->PlayoutFrameCompleted(completion); }, videoModes.output, mRuntimeStore && mRuntimeStore->ExternalKeyingEnabled(), initFailureReason)) { goto error; } @@ -237,7 +239,7 @@ void OpenGLComposite::paintGL(bool force) if (IsIconic(hGLWnd)) return; - const unsigned previewFps = mRuntimeHost ? mRuntimeHost->GetPreviewFps() : 30u; + const unsigned previewFps = mRuntimeStore ? mRuntimeStore->GetPreviewFps() : 30u; if (previewFps == 0) return; @@ -292,7 +294,7 @@ void OpenGLComposite::PublishVideoIOStatus(const std::string& statusMessage) mVideoIO->SupportsInternalKeying(), mVideoIO->SupportsExternalKeying(), mVideoIO->KeyerInterfaceAvailable(), - mRuntimeHost->ExternalKeyingEnabled(), + mRuntimeStore ? mRuntimeStore->ExternalKeyingEnabled() : false, mVideoIO->ExternalKeyingActive(), mVideoIO->StatusMessage()); } @@ -303,7 +305,7 @@ bool OpenGLComposite::InitOpenGLState() return false; std::string runtimeError; - if (mRuntimeHost->GetRepoRoot().empty() && !mRuntimeHost->Initialize(runtimeError)) + if (mRuntimeStore->GetRepoRoot().empty() && !mRuntimeStore->Initialize(runtimeError)) { MessageBoxA(NULL, runtimeError.c_str(), "Runtime host failed to initialize", MB_OK); return false; @@ -381,8 +383,8 @@ bool OpenGLComposite::ReloadShader(bool preserveFeedbackState) mPreserveFeedbackOnNextShaderBuild = preserveFeedbackState; if (mRuntimeHost) { - mRuntimeHost->SetCompileStatus(true, "Shader rebuild queued."); - mRuntimeHost->ClearReloadRequest(); + mRuntimeStore->SetCompileStatus(true, "Shader rebuild queued."); + mRuntimeStore->ClearReloadRequest(); } RequestShaderBuild(); broadcastRuntimeState(); @@ -456,7 +458,7 @@ void OpenGLComposite::renderEffect() if (states.empty() || mOscOverlayStates.empty() || !mRuntimeHost) return; - const double smoothing = ClampOscAlpha(mRuntimeHost->GetOscSmoothing()); + const double smoothing = ClampOscAlpha(mRuntimeStore ? mRuntimeStore->GetOscSmoothing() : 0.0); std::vector overlayKeysToRemove; for (auto& item : mOscOverlayStates) { @@ -591,15 +593,15 @@ void OpenGLComposite::renderEffect() { layerStates = mShaderPrograms->CommittedLayerStates(); applyOscOverlays(layerStates, false); - if (mRuntimeHost) - mRuntimeHost->RefreshDynamicRenderStateFields(layerStates); + if (mRuntimeSnapshotProvider) + mRuntimeSnapshotProvider->RefreshDynamicRenderStateFields(layerStates); } - else if (mRuntimeHost) + else if (mRuntimeSnapshotProvider) { const unsigned renderWidth = mVideoIO->InputFrameWidth(); const unsigned renderHeight = mVideoIO->InputFrameHeight(); - const uint64_t renderStateVersion = mRuntimeHost->GetRenderStateVersion(); - const uint64_t parameterStateVersion = mRuntimeHost->GetParameterStateVersion(); + const uint64_t renderStateVersion = mRuntimeSnapshotProvider->GetRenderStateVersion(); + const uint64_t parameterStateVersion = mRuntimeSnapshotProvider->GetParameterStateVersion(); const bool renderStateCacheValid = !mCachedLayerRenderStates.empty() && mCachedRenderStateVersion == renderStateVersion && @@ -610,17 +612,17 @@ void OpenGLComposite::renderEffect() { applyOscOverlays(mCachedLayerRenderStates, true); if (mCachedParameterStateVersion != parameterStateVersion && - mRuntimeHost->TryRefreshCachedLayerStates(mCachedLayerRenderStates)) + mRuntimeSnapshotProvider->TryRefreshCachedLayerStates(mCachedLayerRenderStates)) { mCachedParameterStateVersion = parameterStateVersion; applyOscOverlays(mCachedLayerRenderStates, true); } layerStates = mCachedLayerRenderStates; - mRuntimeHost->RefreshDynamicRenderStateFields(layerStates); + mRuntimeSnapshotProvider->RefreshDynamicRenderStateFields(layerStates); } else { - if (mRuntimeHost->TryGetLayerRenderStates(renderWidth, renderHeight, layerStates)) + if (mRuntimeSnapshotProvider->TryGetLayerRenderStates(renderWidth, renderHeight, layerStates)) { mCachedLayerRenderStates = layerStates; mCachedRenderStateVersion = renderStateVersion; @@ -634,11 +636,11 @@ void OpenGLComposite::renderEffect() { applyOscOverlays(mCachedLayerRenderStates, true); layerStates = mCachedLayerRenderStates; - mRuntimeHost->RefreshDynamicRenderStateFields(layerStates); + mRuntimeSnapshotProvider->RefreshDynamicRenderStateFields(layerStates); } } } - const unsigned historyCap = mRuntimeHost ? mRuntimeHost->GetMaxTemporalHistoryFrames() : 0; + const unsigned historyCap = mRuntimeStore ? mRuntimeStore->GetMaxTemporalHistoryFrames() : 0; mRenderPass->Render( hasInputSource, layerStates, @@ -699,8 +701,8 @@ void OpenGLComposite::ProcessScreenshotRequest() std::filesystem::path OpenGLComposite::BuildScreenshotPath() const { - const std::filesystem::path root = mRuntimeHost && !mRuntimeHost->GetRuntimeRoot().empty() - ? mRuntimeHost->GetRuntimeRoot() + const std::filesystem::path root = mRuntimeStore && !mRuntimeStore->GetRuntimeRoot().empty() + ? mRuntimeStore->GetRuntimeRoot() : std::filesystem::current_path(); const auto now = std::chrono::system_clock::now(); @@ -726,7 +728,7 @@ bool OpenGLComposite::ProcessRuntimePollResults() const RuntimePollEvents events = mRuntimeServices->ConsumePollEvents(); if (events.failed) { - mRuntimeHost->SetCompileStatus(false, events.error); + mRuntimeStore->SetCompileStatus(false, events.error); broadcastRuntimeState(); return false; } @@ -743,7 +745,7 @@ bool OpenGLComposite::ProcessRuntimePollResults() char compilerErrorMessage[1024] = {}; if (!mShaderPrograms->CommitPreparedLayerPrograms(readyBuild, mVideoIO->InputFrameWidth(), mVideoIO->InputFrameHeight(), sizeof(compilerErrorMessage), compilerErrorMessage)) { - mRuntimeHost->SetCompileStatus(false, compilerErrorMessage); + mRuntimeStore->SetCompileStatus(false, compilerErrorMessage); mUseCommittedLayerStates = true; mPreserveFeedbackOnNextShaderBuild = false; broadcastRuntimeState(); @@ -760,7 +762,7 @@ bool OpenGLComposite::ProcessRuntimePollResults() return true; } - mRuntimeHost->SetCompileStatus(true, "Shader rebuild queued."); + mRuntimeStore->SetCompileStatus(true, "Shader rebuild queued."); mPreserveFeedbackOnNextShaderBuild = false; RequestShaderBuild(); broadcastRuntimeState(); @@ -774,7 +776,7 @@ void OpenGLComposite::RequestShaderBuild() mUseCommittedLayerStates = true; if (mRuntimeHost) - mRuntimeHost->ClearReloadRequest(); + mRuntimeStore->ClearReloadRequest(); mShaderBuildQueue->RequestBuild(mVideoIO->InputFrameWidth(), mVideoIO->InputFrameHeight()); } diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.h b/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.h index 7f103f5..1e41bab 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.h +++ b/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLComposite.h @@ -14,6 +14,8 @@ #include "GLExtensions.h" #include "OpenGLRenderer.h" #include "RuntimeHost.h" +#include "RuntimeSnapshotProvider.h" +#include "RuntimeStore.h" #include #include @@ -95,6 +97,8 @@ private: std::unique_ptr mVideoIO; std::unique_ptr mRenderer; std::unique_ptr mRuntimeHost; + std::unique_ptr mRuntimeStore; + std::unique_ptr mRuntimeSnapshotProvider; std::unique_ptr mVideoIOBridge; std::unique_ptr mRenderPass; std::unique_ptr mRenderPipeline; diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLCompositeRuntimeControls.cpp b/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLCompositeRuntimeControls.cpp index 4adc0ec..49d1509 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLCompositeRuntimeControls.cpp +++ b/apps/LoopThroughWithOpenGLCompositing/gl/OpenGLCompositeRuntimeControls.cpp @@ -3,22 +3,22 @@ std::string OpenGLComposite::GetRuntimeStateJson() const { - return mRuntimeHost ? mRuntimeHost->BuildStateJson() : "{}"; + return mRuntimeStore ? mRuntimeStore->BuildStateJson() : "{}"; } unsigned short OpenGLComposite::GetControlServerPort() const { - return mRuntimeHost ? mRuntimeHost->GetServerPort() : 0; + return mRuntimeStore ? mRuntimeStore->GetServerPort() : 0; } unsigned short OpenGLComposite::GetOscPort() const { - return mRuntimeHost ? mRuntimeHost->GetOscPort() : 0; + return mRuntimeStore ? mRuntimeStore->GetOscPort() : 0; } std::string OpenGLComposite::GetOscBindAddress() const { - return mRuntimeHost ? mRuntimeHost->GetOscBindAddress() : "127.0.0.1"; + return mRuntimeStore ? mRuntimeStore->GetOscBindAddress() : "127.0.0.1"; } std::string OpenGLComposite::GetControlUrl() const @@ -38,7 +38,7 @@ std::string OpenGLComposite::GetOscAddress() const bool OpenGLComposite::AddLayer(const std::string& shaderId, std::string& error) { - if (!mRuntimeHost->AddLayer(shaderId, error)) + if (!mRuntimeStore->AddLayer(shaderId, error)) return false; ReloadShader(true); @@ -48,7 +48,7 @@ bool OpenGLComposite::AddLayer(const std::string& shaderId, std::string& error) bool OpenGLComposite::RemoveLayer(const std::string& layerId, std::string& error) { - if (!mRuntimeHost->RemoveLayer(layerId, error)) + if (!mRuntimeStore->RemoveLayer(layerId, error)) return false; ReloadShader(true); @@ -58,7 +58,7 @@ bool OpenGLComposite::RemoveLayer(const std::string& layerId, std::string& error bool OpenGLComposite::MoveLayer(const std::string& layerId, int direction, std::string& error) { - if (!mRuntimeHost->MoveLayer(layerId, direction, error)) + if (!mRuntimeStore->MoveLayer(layerId, direction, error)) return false; ReloadShader(true); @@ -68,7 +68,7 @@ bool OpenGLComposite::MoveLayer(const std::string& layerId, int direction, std:: bool OpenGLComposite::MoveLayerToIndex(const std::string& layerId, std::size_t targetIndex, std::string& error) { - if (!mRuntimeHost->MoveLayerToIndex(layerId, targetIndex, error)) + if (!mRuntimeStore->MoveLayerToIndex(layerId, targetIndex, error)) return false; ReloadShader(true); @@ -78,7 +78,7 @@ bool OpenGLComposite::MoveLayerToIndex(const std::string& layerId, std::size_t t bool OpenGLComposite::SetLayerBypass(const std::string& layerId, bool bypassed, std::string& error) { - if (!mRuntimeHost->SetLayerBypass(layerId, bypassed, error)) + if (!mRuntimeStore->SetLayerBypass(layerId, bypassed, error)) return false; ReloadShader(); @@ -88,7 +88,7 @@ bool OpenGLComposite::SetLayerBypass(const std::string& layerId, bool bypassed, bool OpenGLComposite::SetLayerShader(const std::string& layerId, const std::string& shaderId, std::string& error) { - if (!mRuntimeHost->SetLayerShader(layerId, shaderId, error)) + if (!mRuntimeStore->SetLayerShader(layerId, shaderId, error)) return false; ReloadShader(); @@ -102,7 +102,7 @@ bool OpenGLComposite::UpdateLayerParameterJson(const std::string& layerId, const if (!ParseJson(valueJson, parsedValue, error)) return false; - if (!mRuntimeHost->UpdateLayerParameter(layerId, parameterId, parsedValue, error)) + if (!mRuntimeStore->UpdateLayerParameter(layerId, parameterId, parsedValue, error)) return false; broadcastRuntimeState(); @@ -115,7 +115,7 @@ bool OpenGLComposite::UpdateLayerParameterByControlKeyJson(const std::string& la if (!ParseJson(valueJson, parsedValue, error)) return false; - if (!mRuntimeHost->UpdateLayerParameterByControlKey(layerKey, parameterKey, parsedValue, error)) + if (!mRuntimeStore->UpdateLayerParameterByControlKey(layerKey, parameterKey, parsedValue, error)) return false; broadcastRuntimeState(); @@ -124,7 +124,7 @@ bool OpenGLComposite::UpdateLayerParameterByControlKeyJson(const std::string& la bool OpenGLComposite::ResetLayerParameters(const std::string& layerId, std::string& error) { - if (!mRuntimeHost->ResetLayerParameters(layerId, error)) + if (!mRuntimeStore->ResetLayerParameters(layerId, error)) return false; mOscOverlayStates.clear(); @@ -138,7 +138,7 @@ bool OpenGLComposite::ResetLayerParameters(const std::string& layerId, std::stri bool OpenGLComposite::SaveStackPreset(const std::string& presetName, std::string& error) { - if (!mRuntimeHost->SaveStackPreset(presetName, error)) + if (!mRuntimeStore->SaveStackPreset(presetName, error)) return false; broadcastRuntimeState(); @@ -147,7 +147,7 @@ bool OpenGLComposite::SaveStackPreset(const std::string& presetName, std::string bool OpenGLComposite::LoadStackPreset(const std::string& presetName, std::string& error) { - if (!mRuntimeHost->LoadStackPreset(presetName, error)) + if (!mRuntimeStore->LoadStackPreset(presetName, error)) return false; ReloadShader(); diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.cpp b/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.cpp index 61a6e7e..78f2388 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.cpp +++ b/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.cpp @@ -29,9 +29,10 @@ std::size_t RequiredTemporaryRenderTargets(const std::vector layerStates = mRuntimeHost.GetLayerRenderStates(inputFrameWidth, inputFrameHeight); + const std::vector layerStates = mRuntimeSnapshotProvider.GetLayerRenderStates(inputFrameWidth, inputFrameHeight); std::string temporalError; const unsigned historyCap = mRuntimeHost.GetMaxTemporalHistoryFrames(); if (!mRenderer.TemporalHistory().ValidateTextureUnitBudget(layerStates, historyCap, temporalError)) diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.h b/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.h index da17519..20b1f16 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.h +++ b/apps/LoopThroughWithOpenGLCompositing/gl/shader/OpenGLShaderPrograms.h @@ -3,6 +3,7 @@ #include "GlobalParamsBuffer.h" #include "OpenGLRenderer.h" #include "RuntimeHost.h" +#include "RuntimeSnapshotProvider.h" #include "ShaderBuildQueue.h" #include "ShaderTypes.h" #include "ShaderProgramCompiler.h" @@ -15,7 +16,7 @@ class OpenGLShaderPrograms public: using LayerProgram = OpenGLRenderer::LayerProgram; - OpenGLShaderPrograms(OpenGLRenderer& renderer, RuntimeHost& runtimeHost); + OpenGLShaderPrograms(OpenGLRenderer& renderer, RuntimeHost& runtimeHost, RuntimeSnapshotProvider& runtimeSnapshotProvider); bool CompileLayerPrograms(unsigned inputFrameWidth, unsigned inputFrameHeight, int errorMessageSize, char* errorMessage); bool CommitPreparedLayerPrograms(const PreparedShaderBuild& preparedBuild, unsigned inputFrameWidth, unsigned inputFrameHeight, int errorMessageSize, char* errorMessage); @@ -33,6 +34,7 @@ public: private: OpenGLRenderer& mRenderer; RuntimeHost& mRuntimeHost; + RuntimeSnapshotProvider& mRuntimeSnapshotProvider; ShaderTextureBindings mTextureBindings; GlobalParamsBuffer mGlobalParamsBuffer; ShaderProgramCompiler mCompiler; diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.cpp b/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.cpp index 801279a..35c1bd8 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.cpp +++ b/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.cpp @@ -1,7 +1,5 @@ #include "ShaderBuildQueue.h" -#include "RuntimeHost.h" - #include #include @@ -10,8 +8,8 @@ namespace constexpr auto kShaderBuildDebounce = std::chrono::milliseconds(400); } -ShaderBuildQueue::ShaderBuildQueue(RuntimeHost& runtimeHost) : - mRuntimeHost(runtimeHost), +ShaderBuildQueue::ShaderBuildQueue(RuntimeSnapshotProvider& runtimeSnapshotProvider) : + mRuntimeSnapshotProvider(runtimeSnapshotProvider), mWorkerThread([this]() { WorkerLoop(); }) { } @@ -113,14 +111,14 @@ PreparedShaderBuild ShaderBuildQueue::Build(uint64_t generation, unsigned output { PreparedShaderBuild build; build.generation = generation; - build.layerStates = mRuntimeHost.GetLayerRenderStates(outputWidth, outputHeight); + build.layerStates = mRuntimeSnapshotProvider.GetLayerRenderStates(outputWidth, outputHeight); build.layers.reserve(build.layerStates.size()); for (const RuntimeRenderState& state : build.layerStates) { PreparedLayerShader layer; layer.state = state; - if (!mRuntimeHost.BuildLayerPassFragmentShaderSources(state.layerId, layer.passes, build.message)) + if (!mRuntimeSnapshotProvider.BuildLayerPassFragmentShaderSources(state.layerId, layer.passes, build.message)) { build.succeeded = false; return build; diff --git a/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.h b/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.h index 513a2cd..1fcec45 100644 --- a/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.h +++ b/apps/LoopThroughWithOpenGLCompositing/gl/shader/ShaderBuildQueue.h @@ -1,5 +1,6 @@ #pragma once +#include "RuntimeSnapshotProvider.h" #include "ShaderTypes.h" #include @@ -9,8 +10,6 @@ #include #include -class RuntimeHost; - struct PreparedLayerShader { RuntimeRenderState state; @@ -29,7 +28,7 @@ struct PreparedShaderBuild class ShaderBuildQueue { public: - explicit ShaderBuildQueue(RuntimeHost& runtimeHost); + explicit ShaderBuildQueue(RuntimeSnapshotProvider& runtimeSnapshotProvider); ~ShaderBuildQueue(); ShaderBuildQueue(const ShaderBuildQueue&) = delete; @@ -43,7 +42,7 @@ private: void WorkerLoop(); PreparedShaderBuild Build(uint64_t generation, unsigned outputWidth, unsigned outputHeight); - RuntimeHost& mRuntimeHost; + RuntimeSnapshotProvider& mRuntimeSnapshotProvider; std::thread mWorkerThread; std::mutex mMutex; std::condition_variable mCondition; diff --git a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp new file mode 100644 index 0000000..5cd1802 --- /dev/null +++ b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.cpp @@ -0,0 +1,41 @@ +#include "RuntimeSnapshotProvider.h" + +RuntimeSnapshotProvider::RuntimeSnapshotProvider(RuntimeHost& runtimeHost) : + mRuntimeHost(runtimeHost) +{ +} + +bool RuntimeSnapshotProvider::BuildLayerPassFragmentShaderSources(const std::string& layerId, std::vector& passSources, std::string& error) const +{ + return mRuntimeHost.BuildLayerPassFragmentShaderSources(layerId, passSources, error); +} + +std::vector RuntimeSnapshotProvider::GetLayerRenderStates(unsigned outputWidth, unsigned outputHeight) const +{ + return mRuntimeHost.GetLayerRenderStates(outputWidth, outputHeight); +} + +bool RuntimeSnapshotProvider::TryGetLayerRenderStates(unsigned outputWidth, unsigned outputHeight, std::vector& states) const +{ + return mRuntimeHost.TryGetLayerRenderStates(outputWidth, outputHeight, states); +} + +bool RuntimeSnapshotProvider::TryRefreshCachedLayerStates(std::vector& states) const +{ + return mRuntimeHost.TryRefreshCachedLayerStates(states); +} + +void RuntimeSnapshotProvider::RefreshDynamicRenderStateFields(std::vector& states) const +{ + mRuntimeHost.RefreshDynamicRenderStateFields(states); +} + +uint64_t RuntimeSnapshotProvider::GetRenderStateVersion() const +{ + return mRuntimeHost.GetRenderStateVersion(); +} + +uint64_t RuntimeSnapshotProvider::GetParameterStateVersion() const +{ + return mRuntimeHost.GetParameterStateVersion(); +} diff --git a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h new file mode 100644 index 0000000..f7555a0 --- /dev/null +++ b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeSnapshotProvider.h @@ -0,0 +1,24 @@ +#pragma once + +#include "RuntimeHost.h" + +#include +#include +#include + +class RuntimeSnapshotProvider +{ +public: + explicit RuntimeSnapshotProvider(RuntimeHost& runtimeHost); + + bool BuildLayerPassFragmentShaderSources(const std::string& layerId, std::vector& passSources, std::string& error) 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: + RuntimeHost& mRuntimeHost; +}; diff --git a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.cpp b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.cpp new file mode 100644 index 0000000..465a5da --- /dev/null +++ b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.cpp @@ -0,0 +1,161 @@ +#include "RuntimeStore.h" + +RuntimeStore::RuntimeStore(RuntimeHost& runtimeHost) : + mRuntimeHost(runtimeHost) +{ +} + +bool RuntimeStore::Initialize(std::string& error) +{ + return mRuntimeHost.Initialize(error); +} + +bool RuntimeStore::AddLayer(const std::string& shaderId, std::string& error) +{ + return mRuntimeHost.AddLayer(shaderId, error); +} + +bool RuntimeStore::RemoveLayer(const std::string& layerId, std::string& error) +{ + return mRuntimeHost.RemoveLayer(layerId, error); +} + +bool RuntimeStore::MoveLayer(const std::string& layerId, int direction, std::string& error) +{ + return mRuntimeHost.MoveLayer(layerId, direction, error); +} + +bool RuntimeStore::MoveLayerToIndex(const std::string& layerId, std::size_t targetIndex, std::string& error) +{ + return mRuntimeHost.MoveLayerToIndex(layerId, targetIndex, error); +} + +bool RuntimeStore::SetLayerBypass(const std::string& layerId, bool bypassed, std::string& error) +{ + return mRuntimeHost.SetLayerBypass(layerId, bypassed, error); +} + +bool RuntimeStore::SetLayerShader(const std::string& layerId, const std::string& shaderId, std::string& error) +{ + return mRuntimeHost.SetLayerShader(layerId, shaderId, error); +} + +bool RuntimeStore::UpdateLayerParameter(const std::string& layerId, const std::string& parameterId, const JsonValue& newValue, std::string& error) +{ + return mRuntimeHost.UpdateLayerParameter(layerId, parameterId, newValue, error); +} + +bool RuntimeStore::UpdateLayerParameterByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue, std::string& error) +{ + return mRuntimeHost.UpdateLayerParameterByControlKey(layerKey, parameterKey, newValue, error); +} + +bool RuntimeStore::UpdateLayerParameterByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue, bool persistState, std::string& error) +{ + return mRuntimeHost.UpdateLayerParameterByControlKey(layerKey, parameterKey, newValue, persistState, error); +} + +bool RuntimeStore::ResetLayerParameters(const std::string& layerId, std::string& error) +{ + return mRuntimeHost.ResetLayerParameters(layerId, error); +} + +bool RuntimeStore::SaveStackPreset(const std::string& presetName, std::string& error) const +{ + return mRuntimeHost.SaveStackPreset(presetName, error); +} + +bool RuntimeStore::LoadStackPreset(const std::string& presetName, std::string& error) +{ + return mRuntimeHost.LoadStackPreset(presetName, error); +} + +std::string RuntimeStore::BuildStateJson() const +{ + return mRuntimeHost.BuildStateJson(); +} + +const std::filesystem::path& RuntimeStore::GetRepoRoot() const +{ + return mRuntimeHost.GetRepoRoot(); +} + +const std::filesystem::path& RuntimeStore::GetUiRoot() const +{ + return mRuntimeHost.GetUiRoot(); +} + +const std::filesystem::path& RuntimeStore::GetDocsRoot() const +{ + return mRuntimeHost.GetDocsRoot(); +} + +const std::filesystem::path& RuntimeStore::GetRuntimeRoot() const +{ + return mRuntimeHost.GetRuntimeRoot(); +} + +unsigned short RuntimeStore::GetServerPort() const +{ + return mRuntimeHost.GetServerPort(); +} + +unsigned short RuntimeStore::GetOscPort() const +{ + return mRuntimeHost.GetOscPort(); +} + +const std::string& RuntimeStore::GetOscBindAddress() const +{ + return mRuntimeHost.GetOscBindAddress(); +} + +double RuntimeStore::GetOscSmoothing() const +{ + return mRuntimeHost.GetOscSmoothing(); +} + +unsigned RuntimeStore::GetMaxTemporalHistoryFrames() const +{ + return mRuntimeHost.GetMaxTemporalHistoryFrames(); +} + +unsigned RuntimeStore::GetPreviewFps() const +{ + return mRuntimeHost.GetPreviewFps(); +} + +bool RuntimeStore::ExternalKeyingEnabled() const +{ + return mRuntimeHost.ExternalKeyingEnabled(); +} + +const std::string& RuntimeStore::GetInputVideoFormat() const +{ + return mRuntimeHost.GetInputVideoFormat(); +} + +const std::string& RuntimeStore::GetInputFrameRate() const +{ + return mRuntimeHost.GetInputFrameRate(); +} + +const std::string& RuntimeStore::GetOutputVideoFormat() const +{ + return mRuntimeHost.GetOutputVideoFormat(); +} + +const std::string& RuntimeStore::GetOutputFrameRate() const +{ + return mRuntimeHost.GetOutputFrameRate(); +} + +void RuntimeStore::SetCompileStatus(bool succeeded, const std::string& message) +{ + mRuntimeHost.SetCompileStatus(succeeded, message); +} + +void RuntimeStore::ClearReloadRequest() +{ + mRuntimeHost.ClearReloadRequest(); +} diff --git a/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.h b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.h new file mode 100644 index 0000000..9532282 --- /dev/null +++ b/apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeStore.h @@ -0,0 +1,51 @@ +#pragma once + +#include "RuntimeHost.h" + +#include +#include + +class RuntimeStore +{ +public: + explicit RuntimeStore(RuntimeHost& runtimeHost); + + bool Initialize(std::string& error); + + bool AddLayer(const std::string& shaderId, std::string& error); + bool RemoveLayer(const std::string& layerId, std::string& error); + bool MoveLayer(const std::string& layerId, int direction, std::string& error); + bool MoveLayerToIndex(const std::string& layerId, std::size_t targetIndex, std::string& error); + bool SetLayerBypass(const std::string& layerId, bool bypassed, std::string& error); + bool SetLayerShader(const std::string& layerId, const std::string& shaderId, std::string& error); + bool UpdateLayerParameter(const std::string& layerId, const std::string& parameterId, const JsonValue& newValue, std::string& error); + bool UpdateLayerParameterByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue, std::string& error); + bool UpdateLayerParameterByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue, bool persistState, std::string& error); + bool ResetLayerParameters(const std::string& layerId, std::string& error); + bool SaveStackPreset(const std::string& presetName, std::string& error) const; + bool LoadStackPreset(const std::string& presetName, std::string& error); + + std::string BuildStateJson() const; + + const std::filesystem::path& GetRepoRoot() const; + const std::filesystem::path& GetUiRoot() const; + const std::filesystem::path& GetDocsRoot() const; + const std::filesystem::path& GetRuntimeRoot() const; + unsigned short GetServerPort() const; + unsigned short GetOscPort() const; + const std::string& GetOscBindAddress() const; + double GetOscSmoothing() const; + unsigned GetMaxTemporalHistoryFrames() const; + unsigned GetPreviewFps() const; + bool ExternalKeyingEnabled() const; + const std::string& GetInputVideoFormat() const; + const std::string& GetInputFrameRate() const; + const std::string& GetOutputVideoFormat() const; + const std::string& GetOutputFrameRate() const; + + void SetCompileStatus(bool succeeded, const std::string& message); + void ClearReloadRequest(); + +private: + RuntimeHost& mRuntimeHost; +};