Add a thread for background depth drawing (doesn't fit very well in our task model)

This commit is contained in:
Henrik Rydgård committed 2025-01-02 14:07:39 +01:00
1 parent 640d256a2d
commit 3c2167fa15
2 files changed
+30

No files matched your search

+18
View File
@@ -69,6 +69,7 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(32) {
}
if (useDepthRaster_) {
depthDraws_.reserve(256);
depthThread_ = std::thread([this]() { DepthThreadFunc(); });
}
}
@@ -87,6 +88,11 @@ DrawEngineCommon::~DrawEngineCommon() {
delete decoder;
});
ClearSplineBezierWeights();
if (depthThread_.joinable()) {
exitDepthThread_ = true;
depthEnqueueCond_.notify_one();
depthThread_.join();
}
}
void DrawEngineCommon::Init() {
@@ -1071,6 +1077,18 @@ void DrawEngineCommon::FlushQueuedDepth() {
inDepthDrawPass_ = false;
}
void DrawEngineCommon::DepthThreadFunc() {
while (true) {
{
std::unique_lock<std::mutex> lock(depthEnqueueMutex_);
depthEnqueueCond_.wait(lock);
if (exitDepthThread_) {
break;
}
}
}
}
void DrawEngineCommon::DepthRasterTransform(GEPrimitiveType prim, VertexDecoder *dec, uint32_t vertTypeID, int vertexCount) {
if (!gstate.isModeClear() && (!gstate.isDepthTestEnabled() || !gstate.isDepthWriteEnabled())) {
return;
+12
View File
@@ -18,6 +18,8 @@
#pragma once
#include <vector>
#include <mutex>
#include <condition_variable>
#include "Common/CommonTypes.h"
#include "Common/Data/Collections/Hashmaps.h"
@@ -365,6 +367,7 @@ protected:
private:
// Internal implementation details.
void DepthThreadFunc();
inline void EnqueueDepthDraw(const DepthDraw &draw);
inline void ProcessDepthDraw(const DepthDraw &draw);
@@ -381,5 +384,14 @@ private:
double depthRasterPassStart_ = 0.0;
std::thread depthThread_;
bool exitDepthThread_ = false; // notify depthEnqueueCond_ to check this.
bool inDepthDrawPass_ = false;
std::mutex depthEnqueueMutex_;
std::condition_variable depthEnqueueCond_;
bool processingDepthDraw_ = false;
std::mutex depthFinishMutex_;
std::condition_variable depthFinishCond_;
};