Improved how threaded rendering is handled

This commit is contained in:
Magnus Norddahl 2016-06-10 18:43:49 +02:00
parent ffcfe0b54f
commit 07571da98c
4 changed files with 39 additions and 8 deletions

View file

@ -443,8 +443,11 @@ void R_SetDSColorMapLight(FColormap *base_colormap, float light, int shade);
void R_SetTranslationMap(lighttable_t *translation);
// Redirect drawer commands to worker threads
void R_BeginDrawerCommands();
// Wait until all drawers finished executing
void R_FinishDrawerCommands();
void R_EndDrawerCommands();
class DrawerCommandQueue;
@ -530,13 +533,14 @@ class DrawerCommandQueue
std::condition_variable end_condition;
size_t finished_threads = 0;
bool no_threading = false;
int threaded_render = 0;
DrawerThread single_core_thread;
int num_passes = 2;
int rows_in_pass = 540;
void StartThreads();
void StopThreads();
void Finish();
static DrawerCommandQueue *Instance();
@ -551,7 +555,7 @@ public:
static void QueueCommand(Types &&... args)
{
auto queue = Instance();
if (queue->no_threading)
if (queue->threaded_render == 0)
{
T command(std::forward<Types>(args)...);
command.Execute(&queue->single_core_thread);
@ -566,8 +570,12 @@ public:
}
}
// Redirects all drawing commands to worker threads until Finish is called
// Begin/End blocks can be nested.
static void Begin();
// Wait until all worker threads finished executing commands
static void Finish();
static void End();
};
#endif

View file

@ -82,6 +82,21 @@ void* DrawerCommandQueue::AllocMemory(size_t size)
return data;
}
void DrawerCommandQueue::Begin()
{
auto queue = Instance();
queue->Finish();
queue->threaded_render++;
}
void DrawerCommandQueue::End()
{
auto queue = Instance();
queue->Finish();
if (queue->threaded_render > 0)
queue->threaded_render--;
}
void DrawerCommandQueue::Finish()
{
auto queue = Instance();
@ -3515,9 +3530,14 @@ public:
/////////////////////////////////////////////////////////////////////////////
void R_FinishDrawerCommands()
void R_BeginDrawerCommands()
{
DrawerCommandQueue::Finish();
DrawerCommandQueue::Begin();
}
void R_EndDrawerCommands()
{
DrawerCommandQueue::End();
}
void R_DrawColumnP_RGBA_C()

View file

@ -961,6 +961,8 @@ void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas,
R_InitColumnDrawers();
}
R_BeginDrawerCommands();
viewwidth = width;
RenderTarget = canvas;
bRenderingToCanvas = true;
@ -979,7 +981,7 @@ void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas,
R_SetupBuffer ();
screen->Unlock ();
R_FinishDrawerCommands();
R_EndDrawerCommands();
viewactive = savedviewactive;
r_swtruecolor = savedoutputformat;

View file

@ -162,10 +162,11 @@ void FSoftwareRenderer::RenderView(player_t *player)
R_InitColumnDrawers();
}
R_BeginDrawerCommands();
R_RenderActorView (player->mo);
// [RH] Let cameras draw onto textures that were visible this frame.
FCanvasTextureInfo::UpdateAll ();
R_FinishDrawerCommands();
R_EndDrawerCommands();
}
//==========================================================================