Skip to content

Commit a3bcaec

Browse files
committed
Cheap render thread. Almost no affect at all.
But this is a place for a possible perfomance enhancement in future.
1 parent 2269409 commit a3bcaec

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/xrEngine/device.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ void CRenderDevice::End(void)
113113
m_editor->on_load_finished();
114114
}
115115

116+
void CRenderDevice::RenderThreadProc(void* context)
117+
{
118+
auto& device = *static_cast<CRenderDevice*>(context);
119+
while (true)
120+
{
121+
device.renderProcessFrame.Wait();
122+
if (device.mt_bMustExit)
123+
{
124+
device.renderThreadExit.Set();
125+
return;
126+
}
127+
128+
device.seqRender.Process(rp_Render);
129+
device.renderFrameDone.Set();
130+
}
131+
}
132+
116133
void CRenderDevice::SecondaryThreadProc(void* context)
117134
{
118135
auto& device = *static_cast<CRenderDevice*>(context);
@@ -251,7 +268,8 @@ void CRenderDevice::on_idle()
251268
renderTotalReal.Begin();
252269
if (b_is_Active && Begin())
253270
{
254-
seqRender.Process(rp_Render);
271+
renderProcessFrame.Set(); // allow render thread to do its job
272+
renderFrameDone.Wait(); // wait until render thread finish its job
255273
CalcFrameStats();
256274
Statistic->Show();
257275
End(); // Present goes here
@@ -324,6 +342,7 @@ void CRenderDevice::Run()
324342
// Start all threads
325343
mt_bMustExit = FALSE;
326344
thread_spawn(SecondaryThreadProc, "X-RAY Secondary thread", 0, this);
345+
thread_spawn(RenderThreadProc, "X-RAY Render thread", 0, this);
327346
// Message cycle
328347
seqAppStart.Process(rp_AppStart);
329348
GEnv.Render->ClearTarget();
@@ -333,8 +352,11 @@ void CRenderDevice::Run()
333352
seqAppEnd.Process(rp_AppEnd);
334353
// Stop Balance-Thread
335354
mt_bMustExit = TRUE;
355+
renderProcessFrame.Set();
356+
renderThreadExit.Wait();
336357
syncProcessFrame.Set();
337358
syncThreadExit.Wait();
359+
338360
while (mt_bMustExit)
339361
Sleep(0);
340362
}

src/xrEngine/device.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase
225225

226226
private:
227227
static void SecondaryThreadProc(void* context);
228+
static void RenderThreadProc(void* context);
228229

229230
public:
230231
// Scene control
@@ -266,7 +267,8 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase
266267
}
267268

268269
private:
269-
Event syncProcessFrame, syncFrameDone, syncThreadExit;
270+
Event syncProcessFrame, syncFrameDone, syncThreadExit; // Secondary thread events
271+
Event renderProcessFrame, renderFrameDone, renderThreadExit; // Render thread events
270272

271273
public:
272274
volatile BOOL mt_bMustExit;

0 commit comments

Comments
 (0)