Shader ownership change
All checks were successful
CI / React UI Build (push) Successful in 11s
CI / Native Windows Build And Tests (push) Successful in 2m52s
CI / Windows Release Package (push) Successful in 2m59s

This commit is contained in:
Aiden
2026-05-12 02:15:03 +10:00
parent 4ea829af85
commit c0d7e84495
12 changed files with 370 additions and 36 deletions

View File

@@ -93,7 +93,6 @@ void RenderThread::ThreadMain()
SignalStartupFailure("Render pipeline initialization failed.");
return;
}
mSlangCompiler.StartHappyAccidentBuild();
RenderCadenceClock clock(mConfig.frameDurationMilliseconds);
uint64_t frameIndex = 0;
@@ -156,7 +155,6 @@ void RenderThread::ThreadMain()
readback.Shutdown();
runtimeShaderRenderer.ShutdownGl();
renderer.ShutdownGl();
mSlangCompiler.Stop();
window.ClearCurrent();
mRunning.store(false, std::memory_order_release);
}
@@ -193,23 +191,36 @@ void RenderThread::CountAcquireMiss()
++mMetrics.acquireMisses;
}
void RenderThread::SubmitRuntimeShaderArtifact(const RuntimeShaderArtifact& artifact)
{
if (artifact.fragmentShaderSource.empty())
return;
std::lock_guard<std::mutex> lock(mShaderArtifactMutex);
mPendingShaderArtifact = artifact;
mHasPendingShaderArtifact = 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;
}
void RenderThread::TryCommitReadyRuntimeShader(RuntimeShaderRenderer& runtimeShaderRenderer)
{
RuntimeSlangShaderBuild build;
if (!mSlangCompiler.TryConsume(build))
RuntimeShaderArtifact artifact;
if (!TryTakePendingRuntimeShaderArtifact(artifact))
return;
if (!build.succeeded)
{
std::cout << "Runtime Slang build failed: " << build.message << "\n";
OutputDebugStringA(("Runtime Slang build failed: " + build.message + "\n").c_str());
std::lock_guard<std::mutex> lock(mMetricsMutex);
++mMetrics.shaderBuildFailures;
return;
}
std::string commitError;
if (!runtimeShaderRenderer.CommitFragmentShader(build.fragmentShaderSource, commitError))
if (!runtimeShaderRenderer.CommitFragmentShader(artifact.fragmentShaderSource, commitError))
{
std::cout << "Runtime shader GL commit failed: " << commitError << "\n";
OutputDebugStringA(("Runtime shader GL commit failed: " + commitError + "\n").c_str());
@@ -218,8 +229,8 @@ void RenderThread::TryCommitReadyRuntimeShader(RuntimeShaderRenderer& runtimeSha
return;
}
std::cout << "Runtime shader committed: " << build.shaderId << ". " << build.message << "\n";
OutputDebugStringA(("Runtime shader committed: " + build.shaderId + ". " + build.message + "\n").c_str());
std::cout << "Runtime shader committed: " << artifact.shaderId << ". " << artifact.message << "\n";
OutputDebugStringA(("Runtime shader committed: " + artifact.shaderId + ". " + artifact.message + "\n").c_str());
std::lock_guard<std::mutex> lock(mMetricsMutex);
++mMetrics.shaderBuildsCommitted;
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include "RenderCadenceClock.h"
#include "../runtime/RuntimeSlangShaderCompiler.h"
#include "../runtime/RuntimeShaderArtifact.h"
#include "RuntimeShaderRenderer.h"
#include <atomic>
@@ -44,6 +44,7 @@ public:
bool Start(std::string& error);
void Stop();
void SubmitRuntimeShaderArtifact(const RuntimeShaderArtifact& artifact);
Metrics GetMetrics() const;
bool IsRunning() const { return mRunning.load(std::memory_order_acquire); }
@@ -56,10 +57,10 @@ private:
void CountCompleted();
void CountAcquireMiss();
void TryCommitReadyRuntimeShader(RuntimeShaderRenderer& runtimeShaderRenderer);
bool TryTakePendingRuntimeShaderArtifact(RuntimeShaderArtifact& artifact);
SystemFrameExchange& mFrameExchange;
Config mConfig;
RuntimeSlangShaderCompiler mSlangCompiler;
std::thread mThread;
std::atomic<bool> mStopping{ false };
std::atomic<bool> mRunning{ false };
@@ -71,4 +72,8 @@ private:
mutable std::mutex mMetricsMutex;
Metrics mMetrics;
std::mutex mShaderArtifactMutex;
bool mHasPendingShaderArtifact = false;
RuntimeShaderArtifact mPendingShaderArtifact;
};