non-blocking http
All checks were successful
CI / React UI Build (push) Successful in 11s
CI / Native Windows Build And Tests (push) Successful in 2m58s
CI / Windows Release Package (push) Has been skipped

This commit is contained in:
Aiden
2026-05-12 15:05:54 +10:00
parent 95b4a54326
commit c5fd8e72b4
4 changed files with 57 additions and 8 deletions

View File

@@ -50,6 +50,8 @@ void RuntimeLayerController::Stop()
ControlActionResult RuntimeLayerController::HandleAddLayer(const std::string& body)
{
CleanupRetiredShaderBuilds();
std::string shaderId;
std::string error;
if (!ExtractStringField(body, "shaderId", shaderId, error))
@@ -69,6 +71,8 @@ ControlActionResult RuntimeLayerController::HandleAddLayer(const std::string& bo
ControlActionResult RuntimeLayerController::HandleRemoveLayer(const std::string& body)
{
CleanupRetiredShaderBuilds();
std::string layerId;
std::string error;
if (!ExtractStringField(body, "layerId", layerId, error))
@@ -81,7 +85,7 @@ ControlActionResult RuntimeLayerController::HandleRemoveLayer(const std::string&
}
Log("runtime-shader", "Layer removed: " + layerId);
StopLayerShaderBuild(layerId);
RetireLayerShaderBuild(layerId);
PublishRuntimeRenderLayers();
return { true, std::string() };
}
@@ -125,6 +129,9 @@ void RuntimeLayerController::InitializeLayerModel(std::string& runtimeShaderId)
void RuntimeLayerController::StartLayerShaderBuild(const std::string& layerId, const std::string& shaderId)
{
CleanupRetiredShaderBuilds();
RetireLayerShaderBuild(layerId);
{
std::lock_guard<std::mutex> lock(mRuntimeLayerMutex);
std::string error;
@@ -135,9 +142,6 @@ void RuntimeLayerController::StartLayerShaderBuild(const std::string& layerId, c
RuntimeShaderBridge* bridgePtr = bridge.get();
{
std::lock_guard<std::mutex> lock(mShaderBuildMutex);
auto existingIt = mShaderBuilds.find(layerId);
if (existingIt != mShaderBuilds.end())
existingIt->second->Stop();
mShaderBuilds[layerId] = std::move(bridge);
}
@@ -154,7 +158,7 @@ void RuntimeLayerController::StartLayerShaderBuild(const std::string& layerId, c
});
}
void RuntimeLayerController::StopLayerShaderBuild(const std::string& layerId)
void RuntimeLayerController::RetireLayerShaderBuild(const std::string& layerId)
{
std::unique_ptr<RuntimeShaderBridge> bridge;
{
@@ -164,19 +168,45 @@ void RuntimeLayerController::StopLayerShaderBuild(const std::string& layerId)
return;
bridge = std::move(bridgeIt->second);
mShaderBuilds.erase(bridgeIt);
bridge->RequestStop();
mRetiredShaderBuilds.push_back(std::move(bridge));
}
bridge->Stop();
}
void RuntimeLayerController::CleanupRetiredShaderBuilds()
{
std::vector<std::unique_ptr<RuntimeShaderBridge>> readyToStop;
{
std::lock_guard<std::mutex> lock(mShaderBuildMutex);
for (auto it = mRetiredShaderBuilds.begin(); it != mRetiredShaderBuilds.end();)
{
if ((*it)->CanStopWithoutWaiting())
{
readyToStop.push_back(std::move(*it));
it = mRetiredShaderBuilds.erase(it);
continue;
}
++it;
}
}
for (std::unique_ptr<RuntimeShaderBridge>& bridge : readyToStop)
bridge->Stop();
}
void RuntimeLayerController::StopAllRuntimeShaderBuilds()
{
std::map<std::string, std::unique_ptr<RuntimeShaderBridge>> builds;
std::vector<std::unique_ptr<RuntimeShaderBridge>> retiredBuilds;
{
std::lock_guard<std::mutex> lock(mShaderBuildMutex);
builds.swap(mShaderBuilds);
retiredBuilds.swap(mRetiredShaderBuilds);
}
for (auto& entry : builds)
entry.second->Stop();
for (auto& bridge : retiredBuilds)
bridge->Stop();
}
void RuntimeLayerController::PublishRuntimeRenderLayers()

View File

@@ -40,7 +40,8 @@ private:
void LoadSupportedShaderCatalog(const std::string& shaderLibrary, unsigned maxTemporalHistoryFrames);
void InitializeLayerModel(std::string& runtimeShaderId);
void StartLayerShaderBuild(const std::string& layerId, const std::string& shaderId);
void StopLayerShaderBuild(const std::string& layerId);
void RetireLayerShaderBuild(const std::string& layerId);
void CleanupRetiredShaderBuilds();
void StopAllRuntimeShaderBuilds();
void PublishRuntimeRenderLayers();
bool MarkRuntimeBuildReady(const RuntimeShaderArtifact& artifact);
@@ -55,5 +56,6 @@ private:
RuntimeLayerModel mRuntimeLayerModel;
std::mutex mShaderBuildMutex;
std::map<std::string, std::unique_ptr<RuntimeShaderBridge>> mShaderBuilds;
std::vector<std::unique_ptr<RuntimeShaderBridge>> mRetiredShaderBuilds;
};
}

View File

@@ -22,19 +22,31 @@ void RuntimeShaderBridge::Start(const std::string& layerId, const std::string& s
mOnArtifactReady = std::move(onArtifactReady);
mOnError = std::move(onError);
mStopping.store(false, std::memory_order_release);
mFinished.store(false, std::memory_order_release);
mCompiler.StartShaderBuild(shaderId);
mThread = std::thread([this]() { ThreadMain(); });
}
void RuntimeShaderBridge::Stop()
void RuntimeShaderBridge::RequestStop()
{
mStopping.store(true, std::memory_order_release);
}
void RuntimeShaderBridge::Stop()
{
RequestStop();
if (mThread.joinable())
mThread.join();
mCompiler.Stop();
mLayerId.clear();
mOnArtifactReady = ArtifactCallback();
mOnError = ErrorCallback();
mFinished.store(true, std::memory_order_release);
}
bool RuntimeShaderBridge::CanStopWithoutWaiting() const
{
return mFinished.load(std::memory_order_acquire) && !mCompiler.Running();
}
void RuntimeShaderBridge::ThreadMain()
@@ -54,8 +66,10 @@ void RuntimeShaderBridge::ThreadMain()
{
mOnError(build.message);
}
mFinished.store(true, std::memory_order_release);
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
mFinished.store(true, std::memory_order_release);
}

View File

@@ -21,7 +21,9 @@ public:
void Start(const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
void Start(const std::string& layerId, const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
void RequestStop();
void Stop();
bool CanStopWithoutWaiting() const;
private:
void ThreadMain();
@@ -29,6 +31,7 @@ private:
RuntimeSlangShaderCompiler mCompiler;
std::thread mThread;
std::atomic<bool> mStopping{ false };
std::atomic<bool> mFinished{ true };
std::string mLayerId;
ArtifactCallback mOnArtifactReady;
ErrorCallback mOnError;