Skip to content

Commit

Permalink
Cheap render thread. Almost no affect at all.
Browse files Browse the repository at this point in the history
But this is a place for a possible perfomance enhancement in future.
  • Loading branch information
Xottab-DUTY committed Mar 31, 2018
1 parent 2269409 commit a3bcaec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ void CRenderDevice::End(void)
m_editor->on_load_finished();
}

void CRenderDevice::RenderThreadProc(void* context)
{
auto& device = *static_cast<CRenderDevice*>(context);
while (true)
{
device.renderProcessFrame.Wait();
if (device.mt_bMustExit)
{
device.renderThreadExit.Set();
return;
}

device.seqRender.Process(rp_Render);
device.renderFrameDone.Set();
}
}

void CRenderDevice::SecondaryThreadProc(void* context)
{
auto& device = *static_cast<CRenderDevice*>(context);
Expand Down Expand Up @@ -251,7 +268,8 @@ void CRenderDevice::on_idle()
renderTotalReal.Begin();
if (b_is_Active && Begin())
{
seqRender.Process(rp_Render);
renderProcessFrame.Set(); // allow render thread to do its job
renderFrameDone.Wait(); // wait until render thread finish its job
CalcFrameStats();
Statistic->Show();
End(); // Present goes here
Expand Down Expand Up @@ -324,6 +342,7 @@ void CRenderDevice::Run()
// Start all threads
mt_bMustExit = FALSE;
thread_spawn(SecondaryThreadProc, "X-RAY Secondary thread", 0, this);
thread_spawn(RenderThreadProc, "X-RAY Render thread", 0, this);
// Message cycle
seqAppStart.Process(rp_AppStart);
GEnv.Render->ClearTarget();
Expand All @@ -333,8 +352,11 @@ void CRenderDevice::Run()
seqAppEnd.Process(rp_AppEnd);
// Stop Balance-Thread
mt_bMustExit = TRUE;
renderProcessFrame.Set();
renderThreadExit.Wait();
syncProcessFrame.Set();
syncThreadExit.Wait();

while (mt_bMustExit)
Sleep(0);
}
Expand Down
4 changes: 3 additions & 1 deletion src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase

private:
static void SecondaryThreadProc(void* context);
static void RenderThreadProc(void* context);

public:
// Scene control
Expand Down Expand Up @@ -266,7 +267,8 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase
}

private:
Event syncProcessFrame, syncFrameDone, syncThreadExit;
Event syncProcessFrame, syncFrameDone, syncThreadExit; // Secondary thread events
Event renderProcessFrame, renderFrameDone, renderThreadExit; // Render thread events

public:
volatile BOOL mt_bMustExit;
Expand Down

0 comments on commit a3bcaec

Please sign in to comment.