2 Commits

Author SHA1 Message Date
0b6a2300ea Fixes
Some checks failed
CI / React UI Build (push) Successful in 38s
CI / Native Windows Build And Tests (push) Failing after 3m0s
CI / Windows Release Package (push) Has been skipped
2026-05-22 14:43:03 +10:00
084e60cbe0 render thread split 2026-05-21 17:57:29 +10:00
48 changed files with 578 additions and 472 deletions

View File

@@ -25,8 +25,14 @@ set(VIDEO_SHADER_INCLUDE_DIRS
"${SRC_DIR}/preview"
"${SRC_DIR}/render"
"${SRC_DIR}/render/readback"
"${SRC_DIR}/render/thread"
"${SRC_DIR}/render/runtime"
"${SRC_DIR}/runtime"
"${SRC_DIR}/runtime/catalog"
"${SRC_DIR}/runtime/layers"
"${SRC_DIR}/runtime/shader"
"${SRC_DIR}/runtime/state"
"${SRC_DIR}/runtime/text"
"${SRC_DIR}/shader"
"${SRC_DIR}/telemetry"
"${SRC_DIR}/video"
@@ -89,10 +95,10 @@ set(RENDER_CADENCE_APP_REQUIRED_FILES
"${SRC_DIR}/render/GLExtensions.cpp"
"${SRC_DIR}/render/GLExtensions.h"
"${SRC_DIR}/render/Std140Buffer.h"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/RuntimeJson.h"
"${SRC_DIR}/runtime/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/RuntimeParameterUtils.h"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.h"
"${SRC_DIR}/runtime/state/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/state/RuntimeParameterUtils.h"
"${SRC_DIR}/shader/ShaderCompiler.cpp"
"${SRC_DIR}/shader/ShaderCompiler.h"
"${SRC_DIR}/shader/ShaderPackageRegistry.cpp"

View File

@@ -266,8 +266,8 @@ Status: addressed by Phase 6.
Relevant current `RenderCadenceCompositor` code:
- `src/app/RuntimeLayerControllerControls.cpp`
- `src/runtime/RuntimeStatePersistence.cpp`
- `src/runtime/RuntimeStatePersistence.h`
- `src/runtime/state/RuntimeStatePersistence.cpp`
- `src/runtime/state/RuntimeStatePersistence.h`
Runtime-state persistence now flows from accepted durable layer-stack mutations into a debounced background writer. The layer controller owns the current snapshot source, while `RuntimeStatePersistenceWriter` owns serialization, temp-file replacement, coalescing, result reporting, and shutdown flushing.

View File

@@ -21,10 +21,16 @@ The app is a native C++ OpenGL compositor with:
Primary source areas:
- `src/app`: startup/shutdown orchestration, config loading, runtime layer controller
- `src/render`: render thread, readback, runtime GL scene, shared-context shader prepare worker
- `src/render`: cadence clock, input texture upload, simple renderer, readback, and runtime GL support
- `src/render/thread`: render thread lifecycle, cadence loop, metrics, and runtime shader commit mailbox
- `src/render/runtime`: render-thread-owned runtime shader scene, renderer, text texture upload cache, and shared-context shader prepare worker
- `src/frames`: system-memory frame exchange
- `src/video`: DeckLink input/output edges and scheduling
- `src/runtime`: shader catalog support, layer model, Slang build bridge, font atlas build, runtime-state persistence
- `src/runtime/catalog`: supported shader catalog and package filtering
- `src/runtime/layers`: app-side runtime layer model, restore, reload, and render snapshot construction
- `src/runtime/shader`: background Slang build bridge and prepared shader artifact types
- `src/runtime/state`: runtime JSON helpers, parameter normalization, and debounced runtime-state persistence
- `src/runtime/text`: MSDF/MTSDF font atlas build and CPU-side prepared text texture composition
- `src/control`: HTTP routing, command parsing, OpenAPI state JSON
- `src/preview`: optional non-consuming preview window
- `src/telemetry` and `src/logging`: runtime observation and logging

View File

@@ -123,12 +123,14 @@ apps/RenderCadenceCompositor/
Win32Console.h
render/
thread/
RenderThread.cpp
RenderThread.h
RenderCadenceClock.cpp
RenderCadenceClock.h
SimpleMotionRenderer.cpp
SimpleMotionRenderer.h
readback/
Bgra8ReadbackPipeline.cpp
Bgra8ReadbackPipeline.h
PboReadbackRing.cpp

View File

@@ -434,9 +434,14 @@ This app keeps the same core behavior but splits it into modules that can grow:
- `frames/InputFrameMailbox`: non-blocking bounded FIFO CPU input handoff with contiguous-copy fast path for matching row strides
- `render/InputFrameTexture`: render-thread-owned upload of the currently acquired CPU input frame into GL, including raw UYVY8 decode into the shader-visible input texture
- `render/readback/`: PBO-backed BGRA8 readback and completed-frame publication
- `render/thread/`: render thread lifecycle, GL startup/cadence loop, metrics, and runtime layer commit mailbox
- `render/runtime/RuntimeRenderScene`: render-thread-owned GL scene for ready runtime shader layers
- `render/runtime/RuntimeShaderPrepareWorker`: shared-context runtime shader program compile/link worker
- `runtime/`: app-owned shader layer readiness model, runtime Slang build bridge, runtime-state persistence, and completed artifact handoff
- `runtime/catalog/`: supported shader catalog and package filtering
- `runtime/layers/`: app-owned shader layer readiness model, restore/reload reconciliation, and render snapshots
- `runtime/shader/`: runtime Slang build bridge and completed artifact handoff
- `runtime/state/`: runtime JSON helpers, parameter normalization, and debounced runtime-state persistence
- `runtime/text/`: font atlas build and prepared text texture composition
- `control/`: control action results and runtime-state JSON presentation
- `control/http/`: local HTTP API, static UI serving, OpenAPI serving, and WebSocket updates
- `json/`: compact JSON serialization helpers

View File

@@ -4,7 +4,7 @@
#include "frames/InputFrameMailbox.h"
#include "frames/SystemFrameExchange.h"
#include "logging/Logger.h"
#include "render/RenderThread.h"
#include "render/thread/RenderThread.h"
#include "video/DeckLinkInput.h"
#include "video/DeckLinkInputThread.h"
#include "DeckLinkDisplayMode.h"

View File

@@ -2,10 +2,10 @@
#include "../control/ControlActionResult.h"
#include "../control/RuntimeControlCommand.h"
#include "../runtime/RuntimeLayerModel.h"
#include "../runtime/RuntimeStatePersistence.h"
#include "../runtime/RuntimeShaderBridge.h"
#include "../runtime/SupportedShaderCatalog.h"
#include "RuntimeLayerModel.h"
#include "RuntimeStatePersistence.h"
#include "RuntimeShaderBridge.h"
#include "SupportedShaderCatalog.h"
#include "../telemetry/CadenceTelemetry.h"
#include <deque>

View File

@@ -3,8 +3,8 @@
#include "../app/AppConfig.h"
#include "../app/AppConfigProvider.h"
#include "../json/JsonWriter.h"
#include "../runtime/RuntimeLayerModel.h"
#include "../runtime/SupportedShaderCatalog.h"
#include "RuntimeLayerModel.h"
#include "SupportedShaderCatalog.h"
#include "../telemetry/CadenceTelemetryJson.h"
#include <cstdint>

View File

@@ -1,393 +0,0 @@
#include "RenderThread.h"
#include "../frames/InputFrameMailbox.h"
#include "../frames/SystemFrameExchange.h"
#include "../frames/SystemFrameTypes.h"
#include "../logging/Logger.h"
#include "../platform/HiddenGlWindow.h"
#include "InputFrameTexture.h"
#include "readback/Bgra8ReadbackPipeline.h"
#include "GLExtensions.h"
#include "runtime/RuntimeRenderScene.h"
#include "runtime/RuntimeShaderRenderer.h"
#include "SimpleMotionRenderer.h"
#include <algorithm>
#include <memory>
#include <thread>
RenderThread::RenderThread(SystemFrameExchange& frameExchange, Config config) :
mFrameExchange(frameExchange),
mConfig(config)
{
}
RenderThread::RenderThread(SystemFrameExchange& frameExchange, InputFrameMailbox* inputMailbox, Config config) :
mFrameExchange(frameExchange),
mInputMailbox(inputMailbox),
mConfig(config)
{
}
RenderThread::~RenderThread()
{
Stop();
}
bool RenderThread::Start(std::string& error)
{
if (mThread.joinable())
return true;
{
std::lock_guard<std::mutex> lock(mStartupMutex);
mStarted = false;
mStartupError.clear();
}
mStopping.store(false, std::memory_order_release);
mThread = std::thread([this]() { ThreadMain(); });
std::unique_lock<std::mutex> lock(mStartupMutex);
if (!mStartupCondition.wait_for(lock, std::chrono::seconds(3), [this]() {
return mStarted || !mStartupError.empty();
}))
{
error = "Timed out starting render thread.";
return false;
}
if (!mStartupError.empty())
{
error = mStartupError;
lock.unlock();
if (mThread.joinable())
mThread.join();
return false;
}
return true;
}
void RenderThread::Stop()
{
mStopping.store(true, std::memory_order_release);
if (mThread.joinable())
mThread.join();
}
RenderThread::Metrics RenderThread::GetMetrics() const
{
Metrics metrics;
metrics.renderedFrames = mRenderedFrames.load(std::memory_order_relaxed);
metrics.completedReadbacks = mCompletedReadbacks.load(std::memory_order_relaxed);
metrics.acquireMisses = mAcquireMisses.load(std::memory_order_relaxed);
metrics.pboQueueMisses = mPboQueueMisses.load(std::memory_order_relaxed);
metrics.clockOverruns = mClockOverruns.load(std::memory_order_relaxed);
metrics.skippedFrames = mSkippedFrames.load(std::memory_order_relaxed);
metrics.shaderBuildsCommitted = mShaderBuildsCommitted.load(std::memory_order_relaxed);
metrics.shaderBuildFailures = mShaderBuildFailures.load(std::memory_order_relaxed);
metrics.renderFrameMilliseconds = mRenderFrameMilliseconds.load(std::memory_order_relaxed);
metrics.renderFrameBudgetUsedPercent = mRenderFrameBudgetUsedPercent.load(std::memory_order_relaxed);
metrics.renderFrameMaxMilliseconds = mRenderFrameMaxMilliseconds.load(std::memory_order_relaxed);
metrics.readbackQueueMilliseconds = mReadbackQueueMilliseconds.load(std::memory_order_relaxed);
metrics.completedReadbackCopyMilliseconds = mCompletedReadbackCopyMilliseconds.load(std::memory_order_relaxed);
metrics.inputFramesReceived = mInputFramesReceived.load(std::memory_order_relaxed);
metrics.inputFramesDropped = mInputFramesDropped.load(std::memory_order_relaxed);
metrics.inputConsumeMisses = mInputConsumeMisses.load(std::memory_order_relaxed);
metrics.inputUploadMisses = mInputUploadMisses.load(std::memory_order_relaxed);
metrics.inputReadyFrames = mInputReadyFrames.load(std::memory_order_relaxed);
metrics.inputReadingFrames = mInputReadingFrames.load(std::memory_order_relaxed);
metrics.inputLatestAgeMilliseconds = mInputLatestAgeMilliseconds.load(std::memory_order_relaxed);
metrics.inputUploadMilliseconds = mInputUploadMilliseconds.load(std::memory_order_relaxed);
metrics.inputFormatSupported = mInputFormatSupported.load(std::memory_order_relaxed);
metrics.inputSignalPresent = mInputSignalPresent.load(std::memory_order_relaxed);
return metrics;
}
void RenderThread::ThreadMain()
{
RenderCadenceCompositor::TryLog(RenderCadenceCompositor::LogLevel::Log, "render-thread", "Render thread starting.");
HiddenGlWindow window;
std::string error;
if (!window.Create(mConfig.width, mConfig.height, error))
{
SignalStartupFailure(error.empty() ? "OpenGL context creation failed." : error);
return;
}
std::unique_ptr<HiddenGlWindow> prepareWindow = std::make_unique<HiddenGlWindow>();
if (!prepareWindow->CreateShared(mConfig.width, mConfig.height, window.DeviceContext(), window.Context(), error))
{
SignalStartupFailure(error.empty() ? "Runtime shader prepare shared context creation failed." : error);
return;
}
if (!window.MakeCurrent())
{
SignalStartupFailure("OpenGL context creation failed.");
return;
}
if (!ResolveGLExtensions())
{
SignalStartupFailure("OpenGL extension resolution failed.");
return;
}
SimpleMotionRenderer renderer;
RuntimeRenderScene runtimeRenderScene;
Bgra8ReadbackPipeline readback;
InputFrameTexture inputTexture;
if (!runtimeRenderScene.StartPrepareWorker(std::move(prepareWindow), error))
{
SignalStartupFailure(error.empty() ? "Runtime shader prepare worker initialization failed." : error);
return;
}
if (!renderer.InitializeGl(mConfig.width, mConfig.height) || !readback.Initialize(mConfig.width, mConfig.height, mConfig.pboDepth))
{
SignalStartupFailure("Render pipeline initialization failed.");
return;
}
RenderCadenceClock clock(mConfig.frameDurationMilliseconds);
uint64_t frameIndex = 0;
mRunning.store(true, std::memory_order_release);
SignalStarted();
while (!mStopping.load(std::memory_order_acquire))
{
readback.ConsumeCompleted(
[this](SystemFrame& frame) { return mFrameExchange.AcquireForRender(frame); },
[this](const SystemFrame& frame) { return mFrameExchange.PublishCompleted(frame); },
[this]() {
CountAcquireMiss();
},
[this]() { CountCompleted(); });
PublishReadbackMetrics(readback);
const auto now = RenderCadenceClock::Clock::now();
const RenderCadenceClock::Tick tick = clock.Poll(now);
if (!tick.due)
{
if (tick.sleepFor > RenderCadenceClock::Duration::zero())
std::this_thread::sleep_for(tick.sleepFor);
continue;
}
TryCommitReadyRuntimeShader(runtimeRenderScene);
const GLuint videoInputTexture = inputTexture.PollAndUpload(mInputMailbox);
PublishInputMetrics(inputTexture);
if (!readback.RenderAndQueue(frameIndex, [this, &renderer, &runtimeRenderScene, videoInputTexture](uint64_t index) {
if (runtimeRenderScene.HasLayers())
runtimeRenderScene.RenderFrame(index, mConfig.width, mConfig.height, videoInputTexture);
else if (videoInputTexture != 0)
renderer.RenderTexture(videoInputTexture);
else
renderer.RenderFrame(index);
}))
{
mPboQueueMisses.fetch_add(1, std::memory_order_relaxed);
}
PublishReadbackMetrics(readback);
CountRendered();
++frameIndex;
clock.MarkRendered(RenderCadenceClock::Clock::now());
mClockOverruns.store(clock.OverrunCount(), std::memory_order_relaxed);
mSkippedFrames.store(clock.SkippedFrameCount(), std::memory_order_relaxed);
}
for (std::size_t i = 0; i < mConfig.pboDepth * 2; ++i)
{
readback.ConsumeCompleted(
[this](SystemFrame& frame) { return mFrameExchange.AcquireForRender(frame); },
[this](const SystemFrame& frame) { return mFrameExchange.PublishCompleted(frame); },
[this]() {
CountAcquireMiss();
},
[this]() { CountCompleted(); });
PublishReadbackMetrics(readback);
}
readback.Shutdown();
inputTexture.ShutdownGl();
runtimeRenderScene.ShutdownGl();
renderer.ShutdownGl();
window.ClearCurrent();
mRunning.store(false, std::memory_order_release);
RenderCadenceCompositor::TryLog(RenderCadenceCompositor::LogLevel::Log, "render-thread", "Render thread stopped.");
}
void RenderThread::SignalStarted()
{
std::lock_guard<std::mutex> lock(mStartupMutex);
mStarted = true;
mStartupCondition.notify_all();
}
void RenderThread::SignalStartupFailure(const std::string& error)
{
RenderCadenceCompositor::TryLog(RenderCadenceCompositor::LogLevel::Error, "render-thread", error);
std::lock_guard<std::mutex> lock(mStartupMutex);
mStartupError = error;
mStartupCondition.notify_all();
}
void RenderThread::CountRendered()
{
mRenderedFrames.fetch_add(1, std::memory_order_relaxed);
}
void RenderThread::CountCompleted()
{
mCompletedReadbacks.fetch_add(1, std::memory_order_relaxed);
}
void RenderThread::CountAcquireMiss()
{
mAcquireMisses.fetch_add(1, std::memory_order_relaxed);
}
void RenderThread::PublishReadbackMetrics(const Bgra8ReadbackPipeline& readback)
{
const double renderMilliseconds = readback.LastRenderFrameMilliseconds();
mRenderFrameMilliseconds.store(renderMilliseconds, std::memory_order_relaxed);
if (mConfig.frameDurationMilliseconds > 0.0)
{
mRenderFrameBudgetUsedPercent.store(
(renderMilliseconds / mConfig.frameDurationMilliseconds) * 100.0,
std::memory_order_relaxed);
}
else
{
mRenderFrameBudgetUsedPercent.store(0.0, std::memory_order_relaxed);
}
const double previousMax = mRenderFrameMaxMilliseconds.load(std::memory_order_relaxed);
if (renderMilliseconds > previousMax)
mRenderFrameMaxMilliseconds.store(renderMilliseconds, std::memory_order_relaxed);
mReadbackQueueMilliseconds.store(readback.LastReadbackQueueMilliseconds(), std::memory_order_relaxed);
mCompletedReadbackCopyMilliseconds.store(readback.LastCompletedReadbackCopyMilliseconds(), std::memory_order_relaxed);
}
void RenderThread::PublishInputMetrics(const InputFrameTexture& inputTexture)
{
if (mInputMailbox != nullptr)
{
const InputFrameMailboxMetrics mailboxMetrics = mInputMailbox->Metrics();
mInputFramesReceived.store(mailboxMetrics.submittedFrames, std::memory_order_relaxed);
mInputFramesDropped.store(mailboxMetrics.droppedReadyFrames + mailboxMetrics.submitMisses, std::memory_order_relaxed);
mInputConsumeMisses.store(mailboxMetrics.consumeMisses, std::memory_order_relaxed);
mInputReadyFrames.store(mailboxMetrics.readyCount, std::memory_order_relaxed);
mInputReadingFrames.store(mailboxMetrics.readingCount, std::memory_order_relaxed);
mInputLatestAgeMilliseconds.store(mailboxMetrics.latestFrameAgeMilliseconds, std::memory_order_relaxed);
mInputSignalPresent.store(mailboxMetrics.hasSubmittedFrame, std::memory_order_relaxed);
}
else
{
mInputFramesReceived.store(0, std::memory_order_relaxed);
mInputFramesDropped.store(0, std::memory_order_relaxed);
mInputConsumeMisses.store(0, std::memory_order_relaxed);
mInputReadyFrames.store(0, std::memory_order_relaxed);
mInputReadingFrames.store(0, std::memory_order_relaxed);
mInputLatestAgeMilliseconds.store(0.0, std::memory_order_relaxed);
mInputSignalPresent.store(false, std::memory_order_relaxed);
}
mInputUploadMisses.store(inputTexture.UploadMisses(), std::memory_order_relaxed);
mInputUploadMilliseconds.store(inputTexture.LastUploadMilliseconds(), std::memory_order_relaxed);
mInputFormatSupported.store(inputTexture.LastFrameFormatSupported(), std::memory_order_relaxed);
}
void RenderThread::SubmitRuntimeShaderArtifact(const RuntimeShaderArtifact& artifact)
{
if (artifact.fragmentShaderSource.empty())
return;
std::lock_guard<std::mutex> lock(mShaderArtifactMutex);
mPendingShaderArtifact = artifact;
mHasPendingShaderArtifact = true;
}
void RenderThread::SubmitRuntimeRenderLayers(const std::vector<RenderCadenceCompositor::RuntimeRenderLayerModel>& layers)
{
std::lock_guard<std::mutex> lock(mRenderLayersMutex);
mPendingRenderLayers = layers;
mHasPendingRenderLayers = true;
}
bool RenderThread::TryTakePendingRuntimeShaderArtifact(RuntimeShaderArtifact& artifact)
{
std::lock_guard<std::mutex> lock(mShaderArtifactMutex);
if (!mHasPendingShaderArtifact)
return false;
artifact = std::move(mPendingShaderArtifact);
mPendingShaderArtifact = RuntimeShaderArtifact();
mHasPendingShaderArtifact = false;
return true;
}
bool RenderThread::TryTakePendingRenderLayers(std::vector<RenderCadenceCompositor::RuntimeRenderLayerModel>& layers)
{
std::lock_guard<std::mutex> lock(mRenderLayersMutex);
if (!mHasPendingRenderLayers)
return false;
layers = std::move(mPendingRenderLayers);
mPendingRenderLayers.clear();
mHasPendingRenderLayers = false;
return true;
}
void RenderThread::TryCommitReadyRuntimeShader(RuntimeRenderScene& runtimeRenderScene)
{
std::vector<RenderCadenceCompositor::RuntimeRenderLayerModel> layers;
std::string commitError;
if (TryTakePendingRenderLayers(layers))
{
bool structuralChange = false;
if (!runtimeRenderScene.CommitRenderLayers(layers, commitError, &structuralChange))
{
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Error,
"render-thread",
"Runtime render-layer commit failed: " + commitError);
mShaderBuildFailures.fetch_add(1, std::memory_order_relaxed);
return;
}
if (structuralChange)
{
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Log,
"render-thread",
"Runtime render layer snapshot committed.");
mShaderBuildsCommitted.fetch_add(1, std::memory_order_relaxed);
}
return;
}
RuntimeShaderArtifact artifact;
if (!TryTakePendingRuntimeShaderArtifact(artifact))
return;
RenderCadenceCompositor::RuntimeRenderLayerModel layer;
layer.id = artifact.layerId.empty() ? "runtime-layer-1" : artifact.layerId;
layer.shaderId = artifact.shaderId;
layer.artifact = artifact;
layers.push_back(std::move(layer));
if (!runtimeRenderScene.CommitRenderLayers(layers, commitError))
{
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Error,
"render-thread",
"Runtime shader GL commit failed: " + commitError);
mShaderBuildFailures.fetch_add(1, std::memory_order_relaxed);
return;
}
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Log,
"render-thread",
"Runtime shader committed: " + artifact.shaderId + ". " + artifact.message);
mShaderBuildsCommitted.fetch_add(1, std::memory_order_relaxed);
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include "../runtime/RuntimeLayerModel.h"
#include "RuntimeLayerModel.h"
#include "RuntimeShaderPrepareWorker.h"
#include "RuntimeShaderRenderer.h"

View File

@@ -1,6 +1,6 @@
#pragma once
#include "../runtime/RuntimeShaderArtifact.h"
#include "RuntimeShaderArtifact.h"
#include <cstdint>
#include <vector>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "RuntimeShaderProgram.h"
#include "../../runtime/RuntimeLayerModel.h"
#include "RuntimeLayerModel.h"
#include <windows.h>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "GLExtensions.h"
#include "../../runtime/RuntimeShaderArtifact.h"
#include "RuntimeShaderArtifact.h"
#include <string>
#include <vector>

View File

@@ -3,7 +3,7 @@
#include "GLExtensions.h"
#include "RuntimeShaderProgram.h"
#include "RuntimeTextTextureCache.h"
#include "../../runtime/RuntimeShaderArtifact.h"
#include "RuntimeShaderArtifact.h"
#include <cstdint>
#include <string>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "GLExtensions.h"
#include "../../runtime/RuntimeShaderArtifact.h"
#include "RuntimeShaderArtifact.h"
#include <map>
#include <string>

View File

@@ -0,0 +1,127 @@
#include "RenderThread.h"
#include "../frames/InputFrameMailbox.h"
#include "../frames/SystemFrameExchange.h"
#include "../frames/SystemFrameTypes.h"
#include "../logging/Logger.h"
#include "../platform/HiddenGlWindow.h"
#include "InputFrameTexture.h"
#include "readback/Bgra8ReadbackPipeline.h"
#include "GLExtensions.h"
#include "RuntimeRenderScene.h"
#include "SimpleMotionRenderer.h"
#include <memory>
#include <thread>
void RenderThread::ThreadMain()
{
RenderCadenceCompositor::TryLog(RenderCadenceCompositor::LogLevel::Log, "render-thread", "Render thread starting.");
HiddenGlWindow window;
std::string error;
if (!window.Create(mConfig.width, mConfig.height, error))
{
SignalStartupFailure(error.empty() ? "OpenGL context creation failed." : error);
return;
}
std::unique_ptr<HiddenGlWindow> prepareWindow = std::make_unique<HiddenGlWindow>();
if (!prepareWindow->CreateShared(mConfig.width, mConfig.height, window.DeviceContext(), window.Context(), error))
{
SignalStartupFailure(error.empty() ? "Runtime shader prepare shared context creation failed." : error);
return;
}
if (!window.MakeCurrent())
{
SignalStartupFailure("OpenGL context creation failed.");
return;
}
if (!ResolveGLExtensions())
{
SignalStartupFailure("OpenGL extension resolution failed.");
return;
}
SimpleMotionRenderer renderer;
RuntimeRenderScene runtimeRenderScene;
Bgra8ReadbackPipeline readback;
InputFrameTexture inputTexture;
if (!runtimeRenderScene.StartPrepareWorker(std::move(prepareWindow), error))
{
SignalStartupFailure(error.empty() ? "Runtime shader prepare worker initialization failed." : error);
return;
}
if (!renderer.InitializeGl(mConfig.width, mConfig.height) || !readback.Initialize(mConfig.width, mConfig.height, mConfig.pboDepth))
{
SignalStartupFailure("Render pipeline initialization failed.");
return;
}
RenderCadenceClock clock(mConfig.frameDurationMilliseconds);
uint64_t frameIndex = 0;
mRunning.store(true, std::memory_order_release);
SignalStarted();
while (!mStopping.load(std::memory_order_acquire))
{
readback.ConsumeCompleted(
[this](SystemFrame& frame) { return mFrameExchange.AcquireForRender(frame); },
[this](const SystemFrame& frame) { return mFrameExchange.PublishCompleted(frame); },
[this]() {
CountAcquireMiss();
},
[this]() { CountCompleted(); });
PublishReadbackMetrics(readback);
const auto now = RenderCadenceClock::Clock::now();
const RenderCadenceClock::Tick tick = clock.Poll(now);
if (!tick.due)
{
if (tick.sleepFor > RenderCadenceClock::Duration::zero())
std::this_thread::sleep_for(tick.sleepFor);
continue;
}
TryCommitReadyRuntimeShader(runtimeRenderScene);
const GLuint videoInputTexture = inputTexture.PollAndUpload(mInputMailbox);
PublishInputMetrics(inputTexture);
if (!readback.RenderAndQueue(frameIndex, [this, &renderer, &runtimeRenderScene, videoInputTexture](uint64_t index) {
if (runtimeRenderScene.HasLayers())
runtimeRenderScene.RenderFrame(index, mConfig.width, mConfig.height, videoInputTexture);
else if (videoInputTexture != 0)
renderer.RenderTexture(videoInputTexture);
else
renderer.RenderFrame(index);
}))
{
mPboQueueMisses.fetch_add(1, std::memory_order_relaxed);
}
PublishReadbackMetrics(readback);
CountRendered();
++frameIndex;
clock.MarkRendered(RenderCadenceClock::Clock::now());
mClockOverruns.store(clock.OverrunCount(), std::memory_order_relaxed);
mSkippedFrames.store(clock.SkippedFrameCount(), std::memory_order_relaxed);
}
for (std::size_t i = 0; i < mConfig.pboDepth * 2; ++i)
{
readback.ConsumeCompleted(
[this](SystemFrame& frame) { return mFrameExchange.AcquireForRender(frame); },
[this](const SystemFrame& frame) { return mFrameExchange.PublishCompleted(frame); },
[this]() {
CountAcquireMiss();
},
[this]() { CountCompleted(); });
PublishReadbackMetrics(readback);
}
readback.Shutdown();
inputTexture.ShutdownGl();
runtimeRenderScene.ShutdownGl();
renderer.ShutdownGl();
window.ClearCurrent();
mRunning.store(false, std::memory_order_release);
RenderCadenceCompositor::TryLog(RenderCadenceCompositor::LogLevel::Log, "render-thread", "Render thread stopped.");
}

View File

@@ -1,9 +1,9 @@
#pragma once
#include "RenderCadenceClock.h"
#include "../runtime/RuntimeLayerModel.h"
#include "../runtime/RuntimeShaderArtifact.h"
#include "runtime/RuntimeRenderScene.h"
#include "RuntimeLayerModel.h"
#include "RuntimeShaderArtifact.h"
#include "RuntimeRenderScene.h"
#include <atomic>
#include <condition_variable>

View File

@@ -0,0 +1,80 @@
#include "RenderThread.h"
#include "../logging/Logger.h"
#include <chrono>
#include <mutex>
#include <thread>
RenderThread::RenderThread(SystemFrameExchange& frameExchange, Config config) :
mFrameExchange(frameExchange),
mConfig(config)
{
}
RenderThread::RenderThread(SystemFrameExchange& frameExchange, InputFrameMailbox* inputMailbox, Config config) :
mFrameExchange(frameExchange),
mInputMailbox(inputMailbox),
mConfig(config)
{
}
RenderThread::~RenderThread()
{
Stop();
}
bool RenderThread::Start(std::string& error)
{
if (mThread.joinable())
return true;
{
std::lock_guard<std::mutex> lock(mStartupMutex);
mStarted = false;
mStartupError.clear();
}
mStopping.store(false, std::memory_order_release);
mThread = std::thread([this]() { ThreadMain(); });
std::unique_lock<std::mutex> lock(mStartupMutex);
if (!mStartupCondition.wait_for(lock, std::chrono::seconds(3), [this]() {
return mStarted || !mStartupError.empty();
}))
{
error = "Timed out starting render thread.";
return false;
}
if (!mStartupError.empty())
{
error = mStartupError;
lock.unlock();
if (mThread.joinable())
mThread.join();
return false;
}
return true;
}
void RenderThread::Stop()
{
mStopping.store(true, std::memory_order_release);
if (mThread.joinable())
mThread.join();
}
void RenderThread::SignalStarted()
{
std::lock_guard<std::mutex> lock(mStartupMutex);
mStarted = true;
mStartupCondition.notify_all();
}
void RenderThread::SignalStartupFailure(const std::string& error)
{
RenderCadenceCompositor::TryLog(RenderCadenceCompositor::LogLevel::Error, "render-thread", error);
std::lock_guard<std::mutex> lock(mStartupMutex);
mStartupError = error;
mStartupCondition.notify_all();
}

View File

@@ -0,0 +1,101 @@
#include "RenderThread.h"
#include "../frames/InputFrameMailbox.h"
#include "InputFrameTexture.h"
#include "readback/Bgra8ReadbackPipeline.h"
RenderThread::Metrics RenderThread::GetMetrics() const
{
Metrics metrics;
metrics.renderedFrames = mRenderedFrames.load(std::memory_order_relaxed);
metrics.completedReadbacks = mCompletedReadbacks.load(std::memory_order_relaxed);
metrics.acquireMisses = mAcquireMisses.load(std::memory_order_relaxed);
metrics.pboQueueMisses = mPboQueueMisses.load(std::memory_order_relaxed);
metrics.clockOverruns = mClockOverruns.load(std::memory_order_relaxed);
metrics.skippedFrames = mSkippedFrames.load(std::memory_order_relaxed);
metrics.shaderBuildsCommitted = mShaderBuildsCommitted.load(std::memory_order_relaxed);
metrics.shaderBuildFailures = mShaderBuildFailures.load(std::memory_order_relaxed);
metrics.renderFrameMilliseconds = mRenderFrameMilliseconds.load(std::memory_order_relaxed);
metrics.renderFrameBudgetUsedPercent = mRenderFrameBudgetUsedPercent.load(std::memory_order_relaxed);
metrics.renderFrameMaxMilliseconds = mRenderFrameMaxMilliseconds.load(std::memory_order_relaxed);
metrics.readbackQueueMilliseconds = mReadbackQueueMilliseconds.load(std::memory_order_relaxed);
metrics.completedReadbackCopyMilliseconds = mCompletedReadbackCopyMilliseconds.load(std::memory_order_relaxed);
metrics.inputFramesReceived = mInputFramesReceived.load(std::memory_order_relaxed);
metrics.inputFramesDropped = mInputFramesDropped.load(std::memory_order_relaxed);
metrics.inputConsumeMisses = mInputConsumeMisses.load(std::memory_order_relaxed);
metrics.inputUploadMisses = mInputUploadMisses.load(std::memory_order_relaxed);
metrics.inputReadyFrames = mInputReadyFrames.load(std::memory_order_relaxed);
metrics.inputReadingFrames = mInputReadingFrames.load(std::memory_order_relaxed);
metrics.inputLatestAgeMilliseconds = mInputLatestAgeMilliseconds.load(std::memory_order_relaxed);
metrics.inputUploadMilliseconds = mInputUploadMilliseconds.load(std::memory_order_relaxed);
metrics.inputFormatSupported = mInputFormatSupported.load(std::memory_order_relaxed);
metrics.inputSignalPresent = mInputSignalPresent.load(std::memory_order_relaxed);
return metrics;
}
void RenderThread::CountRendered()
{
mRenderedFrames.fetch_add(1, std::memory_order_relaxed);
}
void RenderThread::CountCompleted()
{
mCompletedReadbacks.fetch_add(1, std::memory_order_relaxed);
}
void RenderThread::CountAcquireMiss()
{
mAcquireMisses.fetch_add(1, std::memory_order_relaxed);
}
void RenderThread::PublishReadbackMetrics(const Bgra8ReadbackPipeline& readback)
{
const double renderMilliseconds = readback.LastRenderFrameMilliseconds();
mRenderFrameMilliseconds.store(renderMilliseconds, std::memory_order_relaxed);
if (mConfig.frameDurationMilliseconds > 0.0)
{
mRenderFrameBudgetUsedPercent.store(
(renderMilliseconds / mConfig.frameDurationMilliseconds) * 100.0,
std::memory_order_relaxed);
}
else
{
mRenderFrameBudgetUsedPercent.store(0.0, std::memory_order_relaxed);
}
const double previousMax = mRenderFrameMaxMilliseconds.load(std::memory_order_relaxed);
if (renderMilliseconds > previousMax)
mRenderFrameMaxMilliseconds.store(renderMilliseconds, std::memory_order_relaxed);
mReadbackQueueMilliseconds.store(readback.LastReadbackQueueMilliseconds(), std::memory_order_relaxed);
mCompletedReadbackCopyMilliseconds.store(readback.LastCompletedReadbackCopyMilliseconds(), std::memory_order_relaxed);
}
void RenderThread::PublishInputMetrics(const InputFrameTexture& inputTexture)
{
if (mInputMailbox != nullptr)
{
const InputFrameMailboxMetrics mailboxMetrics = mInputMailbox->Metrics();
mInputFramesReceived.store(mailboxMetrics.submittedFrames, std::memory_order_relaxed);
mInputFramesDropped.store(mailboxMetrics.droppedReadyFrames + mailboxMetrics.submitMisses, std::memory_order_relaxed);
mInputConsumeMisses.store(mailboxMetrics.consumeMisses, std::memory_order_relaxed);
mInputReadyFrames.store(mailboxMetrics.readyCount, std::memory_order_relaxed);
mInputReadingFrames.store(mailboxMetrics.readingCount, std::memory_order_relaxed);
mInputLatestAgeMilliseconds.store(mailboxMetrics.latestFrameAgeMilliseconds, std::memory_order_relaxed);
mInputSignalPresent.store(mailboxMetrics.hasSubmittedFrame, std::memory_order_relaxed);
}
else
{
mInputFramesReceived.store(0, std::memory_order_relaxed);
mInputFramesDropped.store(0, std::memory_order_relaxed);
mInputConsumeMisses.store(0, std::memory_order_relaxed);
mInputReadyFrames.store(0, std::memory_order_relaxed);
mInputReadingFrames.store(0, std::memory_order_relaxed);
mInputLatestAgeMilliseconds.store(0.0, std::memory_order_relaxed);
mInputSignalPresent.store(false, std::memory_order_relaxed);
}
mInputUploadMisses.store(inputTexture.UploadMisses(), std::memory_order_relaxed);
mInputUploadMilliseconds.store(inputTexture.LastUploadMilliseconds(), std::memory_order_relaxed);
mInputFormatSupported.store(inputTexture.LastFrameFormatSupported(), std::memory_order_relaxed);
}

View File

@@ -0,0 +1,102 @@
#include "RenderThread.h"
#include "../logging/Logger.h"
#include <mutex>
#include <utility>
#include <vector>
void RenderThread::SubmitRuntimeShaderArtifact(const RuntimeShaderArtifact& artifact)
{
if (artifact.fragmentShaderSource.empty())
return;
std::lock_guard<std::mutex> lock(mShaderArtifactMutex);
mPendingShaderArtifact = artifact;
mHasPendingShaderArtifact = true;
}
void RenderThread::SubmitRuntimeRenderLayers(const std::vector<RenderCadenceCompositor::RuntimeRenderLayerModel>& layers)
{
std::lock_guard<std::mutex> lock(mRenderLayersMutex);
mPendingRenderLayers = layers;
mHasPendingRenderLayers = true;
}
bool RenderThread::TryTakePendingRuntimeShaderArtifact(RuntimeShaderArtifact& artifact)
{
std::lock_guard<std::mutex> lock(mShaderArtifactMutex);
if (!mHasPendingShaderArtifact)
return false;
artifact = std::move(mPendingShaderArtifact);
mPendingShaderArtifact = RuntimeShaderArtifact();
mHasPendingShaderArtifact = false;
return true;
}
bool RenderThread::TryTakePendingRenderLayers(std::vector<RenderCadenceCompositor::RuntimeRenderLayerModel>& layers)
{
std::lock_guard<std::mutex> lock(mRenderLayersMutex);
if (!mHasPendingRenderLayers)
return false;
layers = std::move(mPendingRenderLayers);
mPendingRenderLayers.clear();
mHasPendingRenderLayers = false;
return true;
}
void RenderThread::TryCommitReadyRuntimeShader(RuntimeRenderScene& runtimeRenderScene)
{
std::vector<RenderCadenceCompositor::RuntimeRenderLayerModel> layers;
std::string commitError;
if (TryTakePendingRenderLayers(layers))
{
bool structuralChange = false;
if (!runtimeRenderScene.CommitRenderLayers(layers, commitError, &structuralChange))
{
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Error,
"render-thread",
"Runtime render-layer commit failed: " + commitError);
mShaderBuildFailures.fetch_add(1, std::memory_order_relaxed);
return;
}
if (structuralChange)
{
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Log,
"render-thread",
"Runtime render layer snapshot committed.");
mShaderBuildsCommitted.fetch_add(1, std::memory_order_relaxed);
}
return;
}
RuntimeShaderArtifact artifact;
if (!TryTakePendingRuntimeShaderArtifact(artifact))
return;
RenderCadenceCompositor::RuntimeRenderLayerModel layer;
layer.id = artifact.layerId.empty() ? "runtime-layer-1" : artifact.layerId;
layer.shaderId = artifact.shaderId;
layer.artifact = artifact;
layers.push_back(std::move(layer));
if (!runtimeRenderScene.CommitRenderLayers(layers, commitError))
{
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Error,
"render-thread",
"Runtime shader GL commit failed: " + commitError);
mShaderBuildFailures.fetch_add(1, std::memory_order_relaxed);
return;
}
RenderCadenceCompositor::TryLog(
RenderCadenceCompositor::LogLevel::Log,
"render-thread",
"Runtime shader committed: " + artifact.shaderId + ". " + artifact.message);
mShaderBuildsCommitted.fetch_add(1, std::memory_order_relaxed);
}

View File

@@ -2,10 +2,20 @@
#include "NativeHandles.h"
#include <string>
#include <windows.h>
namespace RenderCadenceCompositor
{
namespace
{
std::string LastWindowsErrorText()
{
const DWORD errorCode = GetLastError();
return std::to_string(static_cast<unsigned long>(errorCode));
}
}
bool FontAtlasBuilder::RunProcess(const std::string& commandLine, const std::filesystem::path& workingDirectory, std::string& error)
{
STARTUPINFOA startupInfo = {};
@@ -17,7 +27,7 @@ bool FontAtlasBuilder::RunProcess(const std::string& commandLine, const std::fil
if (!CreateProcessA(nullptr, mutableCommandLine.data(), nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, workingDirectory.string().c_str(), &startupInfo, &processInfo))
{
error = "Failed to launch msdf-atlas-gen.exe.";
error = "Failed to launch msdf-atlas-gen.exe. Windows error: " + LastWindowsErrorText() + ".";
return false;
}
@@ -29,7 +39,7 @@ bool FontAtlasBuilder::RunProcess(const std::string& commandLine, const std::fil
GetExitCodeProcess(processHandle.get(), &exitCode);
if (exitCode != 0)
{
error = "msdf-atlas-gen.exe returned a non-zero exit code.";
error = "msdf-atlas-gen.exe returned a non-zero exit code: " + std::to_string(static_cast<unsigned long>(exitCode)) + ".";
return false;
}

View File

@@ -40,18 +40,18 @@ add_video_shader_test(RenderCadenceCompositorRuntimeShaderParamsTests
)
add_video_shader_test(RenderCadenceCompositorRuntimeLayerModelTests
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/RuntimeLayerModel.cpp"
"${SRC_DIR}/runtime/RuntimeLayerReload.cpp"
"${SRC_DIR}/runtime/RuntimeLayerSnapshot.cpp"
"${SRC_DIR}/runtime/RuntimeLayerStateRestore.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/RuntimeTextTextureComposer.cpp"
"${SRC_DIR}/runtime/SupportedShaderCatalog.cpp"
"${SRC_DIR}/runtime/text/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/text/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/text/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/text/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerModel.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerReload.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerSnapshot.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerStateRestore.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/text/RuntimeTextTextureComposer.cpp"
"${SRC_DIR}/runtime/catalog/SupportedShaderCatalog.cpp"
"${SRC_DIR}/shader/ShaderManifestAssets.cpp"
"${SRC_DIR}/shader/ShaderManifestParameters.cpp"
"${SRC_DIR}/shader/ShaderManifestParser.cpp"
@@ -61,17 +61,17 @@ add_video_shader_test(RenderCadenceCompositorRuntimeLayerModelTests
add_video_shader_test(RuntimeStatePersistenceTests
"${SRC_DIR}/logging/Logger.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/RuntimeStatePersistence.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeStatePersistence.cpp"
"${TEST_DIR}/RuntimeStatePersistenceTests.cpp"
)
add_video_shader_test(FontAtlasBuilderTests
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/text/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/text/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/text/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/text/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/shader/ShaderManifestAssets.cpp"
"${SRC_DIR}/shader/ShaderManifestParameters.cpp"
"${SRC_DIR}/shader/ShaderManifestParser.cpp"
@@ -80,12 +80,12 @@ add_video_shader_test(FontAtlasBuilderTests
)
add_video_shader_test(RenderCadenceCompositorSupportedShaderCatalogTests
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/SupportedShaderCatalog.cpp"
"${SRC_DIR}/runtime/text/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/text/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/text/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/text/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/runtime/catalog/SupportedShaderCatalog.cpp"
"${SRC_DIR}/shader/ShaderManifestAssets.cpp"
"${SRC_DIR}/shader/ShaderManifestParameters.cpp"
"${SRC_DIR}/shader/ShaderManifestParser.cpp"
@@ -97,18 +97,18 @@ add_video_shader_test(RenderCadenceCompositorRuntimeStateJsonTests
"${SRC_DIR}/app/AppConfig.cpp"
"${SRC_DIR}/app/AppConfigProvider.cpp"
"${SRC_DIR}/json/JsonWriter.cpp"
"${SRC_DIR}/runtime/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/RuntimeLayerModel.cpp"
"${SRC_DIR}/runtime/RuntimeLayerReload.cpp"
"${SRC_DIR}/runtime/RuntimeLayerSnapshot.cpp"
"${SRC_DIR}/runtime/RuntimeLayerStateRestore.cpp"
"${SRC_DIR}/runtime/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/RuntimeTextTextureComposer.cpp"
"${SRC_DIR}/runtime/SupportedShaderCatalog.cpp"
"${SRC_DIR}/runtime/text/FontAtlasBuilder.cpp"
"${SRC_DIR}/runtime/text/FontAtlasImageLoader.cpp"
"${SRC_DIR}/runtime/text/FontAtlasMetadata.cpp"
"${SRC_DIR}/runtime/text/FontAtlasProcess.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerModel.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerReload.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerSnapshot.cpp"
"${SRC_DIR}/runtime/layers/RuntimeLayerStateRestore.cpp"
"${SRC_DIR}/runtime/state/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/text/RuntimeTextTextureComposer.cpp"
"${SRC_DIR}/runtime/catalog/SupportedShaderCatalog.cpp"
"${SRC_DIR}/shader/ShaderManifestAssets.cpp"
"${SRC_DIR}/shader/ShaderManifestParameters.cpp"
"${SRC_DIR}/shader/ShaderManifestParser.cpp"
@@ -123,7 +123,7 @@ add_video_shader_test(RenderCadenceCompositorHttpControlServerTests
"${SRC_DIR}/control/http/HttpControlServerWebSocket.cpp"
"${SRC_DIR}/json/JsonWriter.cpp"
"${SRC_DIR}/logging/Logger.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${TEST_DIR}/RenderCadenceCompositorHttpControlServerTests.cpp"
)
target_link_libraries(RenderCadenceCompositorHttpControlServerTests PRIVATE Ws2_32)
@@ -131,23 +131,23 @@ target_link_libraries(RenderCadenceCompositorHttpControlServerTests PRIVATE Ws2_
add_video_shader_test(RenderCadenceCompositorAppConfigProviderTests
"${SRC_DIR}/app/AppConfig.cpp"
"${SRC_DIR}/app/AppConfigProvider.cpp"
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${TEST_DIR}/RenderCadenceCompositorAppConfigProviderTests.cpp"
)
add_video_shader_test(RuntimeJsonTests
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${TEST_DIR}/RuntimeJsonTests.cpp"
)
add_video_shader_test(RuntimeParameterUtilsTests
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/RuntimeParameterUtils.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeParameterUtils.cpp"
"${TEST_DIR}/RuntimeParameterUtilsTests.cpp"
)
add_video_shader_test(ShaderPackageRegistryTests
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/shader/ShaderManifestAssets.cpp"
"${SRC_DIR}/shader/ShaderManifestParameters.cpp"
"${SRC_DIR}/shader/ShaderManifestParser.cpp"
@@ -156,7 +156,7 @@ add_video_shader_test(ShaderPackageRegistryTests
)
add_video_shader_test(ShaderSlangValidationTests
"${SRC_DIR}/runtime/RuntimeJson.cpp"
"${SRC_DIR}/runtime/state/RuntimeJson.cpp"
"${SRC_DIR}/shader/ShaderCompiler.cpp"
"${SRC_DIR}/shader/ShaderManifestAssets.cpp"
"${SRC_DIR}/shader/ShaderManifestParameters.cpp"

View File

@@ -32,17 +32,34 @@ std::filesystem::path RepoRoot()
return std::filesystem::current_path();
}
bool HasBundledExecutable(std::filesystem::path& executablePath)
{
return RenderCadenceCompositor::FontAtlasBuilder::FindMsdfAtlasGenExecutable(RepoRoot(), executablePath);
}
bool IsMsdfAtlasGenToolError(const std::string& error)
{
return error.find("msdf-atlas-gen") != std::string::npos;
}
void TestFindsBundledExecutable()
{
std::filesystem::path executablePath;
Expect(
RenderCadenceCompositor::FontAtlasBuilder::FindMsdfAtlasGenExecutable(RepoRoot(), executablePath),
HasBundledExecutable(executablePath),
"bundled msdf-atlas-gen executable is found");
Expect(std::filesystem::exists(executablePath), "bundled msdf-atlas-gen executable exists");
}
void TestBuildsTextOverlayFontAtlas()
{
std::filesystem::path executablePath;
if (!HasBundledExecutable(executablePath))
{
std::cout << "SKIP: msdf-atlas-gen executable is not available; skipping font atlas integration build.\n";
return;
}
const std::filesystem::path repoRoot = RepoRoot();
ShaderPackageRegistry registry(4);
ShaderPackage shaderPackage;
@@ -55,7 +72,16 @@ void TestBuildsTextOverlayFontAtlas()
config.cacheRoot = repoRoot / "runtime" / "test_font_cache";
RenderCadenceCompositor::FontAtlasBuilder builder(config);
std::vector<RenderCadenceCompositor::FontAtlasBuildOutput> outputs;
Expect(builder.BuildPackageFontAtlases(shaderPackage, outputs, error), "text overlay font atlas builds");
if (!builder.BuildPackageFontAtlases(shaderPackage, outputs, error))
{
if (IsMsdfAtlasGenToolError(error))
{
std::cout << "SKIP: msdf-atlas-gen could not run in this environment: " << error << "\n";
return;
}
Expect(false, ("text overlay font atlas builds: " + error).c_str());
return;
}
Expect(outputs.size() == 1, "one font atlas output is produced");
if (!outputs.empty())
{

View File

@@ -1,4 +1,5 @@
#include "SupportedShaderCatalog.h"
#include "ShaderPackageRegistry.h"
#include <filesystem>
#include <iostream>
@@ -45,6 +46,32 @@ std::filesystem::path RepoRoot()
return std::filesystem::current_path();
}
bool CanRunMsdfAtlasGen(std::string& reason)
{
const std::filesystem::path repoRoot = RepoRoot();
std::filesystem::path executablePath;
if (!RenderCadenceCompositor::FontAtlasBuilder::FindMsdfAtlasGenExecutable(repoRoot, executablePath))
{
reason = "msdf-atlas-gen executable is not available";
return false;
}
ShaderPackageRegistry registry(4);
ShaderPackage shaderPackage;
if (!registry.ParseManifest(repoRoot / "shaders" / "text-overlay" / "shader.json", shaderPackage, reason))
return false;
RenderCadenceCompositor::FontAtlasBuildConfig config;
config.repoRoot = repoRoot;
config.cacheRoot = repoRoot / "runtime" / "test_font_cache";
RenderCadenceCompositor::FontAtlasBuilder builder(config);
std::vector<RenderCadenceCompositor::FontAtlasBuildOutput> outputs;
if (!builder.BuildPackageFontAtlases(shaderPackage, outputs, reason))
return false;
return true;
}
void SupportsSinglePassStatelessPackage()
{
const ShaderPackage shaderPackage = MakeSinglePassPackage();
@@ -149,6 +176,13 @@ void SupportsTextParametersWithDeclaredFont()
void BuildsDeclaredFontAtlasesDuringCatalogLoad()
{
std::string msdfReason;
if (!CanRunMsdfAtlasGen(msdfReason))
{
std::cout << "SKIP: msdf-atlas-gen could not run in this environment: " << msdfReason << "\n";
return;
}
RenderCadenceCompositor::SupportedShaderCatalog catalog;
std::string error;
Expect(catalog.Load(RepoRoot() / "shaders", 12, error), "shader catalog loads");