mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-12-11 13:11:48 +00:00
Improved how threaded rendering is handled
This commit is contained in:
parent
ffcfe0b54f
commit
07571da98c
4 changed files with 39 additions and 8 deletions
16
src/r_draw.h
16
src/r_draw.h
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
Loading…
Reference in a new issue