- added r_debug_draw that shows how the software renderer composes its scene

This commit is contained in:
Magnus Norddahl 2018-05-08 22:22:15 +02:00
parent 1b68b69ed8
commit 459f748c4e
3 changed files with 41 additions and 3 deletions

View File

@ -40,6 +40,7 @@ void PeekThreadedErrorPane();
#endif
CVAR(Bool, r_multithreaded, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Int, r_debug_draw, 0, 0);
/////////////////////////////////////////////////////////////////////////////
@ -76,6 +77,23 @@ void DrawerThreads::Execute(DrawerCommandQueuePtr commands)
queue->start_condition.notify_all();
}
void DrawerThreads::ResetDebugDrawPos()
{
auto queue = Instance();
std::unique_lock<std::mutex> start_lock(queue->start_mutex);
bool reached_end = false;
for (auto &thread : queue->threads)
{
if (thread.debug_draw_pos + r_debug_draw * 60 * 2 < queue->debug_draw_end)
reached_end = true;
thread.debug_draw_pos = 0;
}
if (!reached_end)
queue->debug_draw_end += r_debug_draw;
else
queue->debug_draw_end = 0;
}
void DrawerThreads::WaitForWorkers()
{
using namespace std::chrono_literals;
@ -124,9 +142,21 @@ void DrawerThreads::WorkerMain(DrawerThread *thread)
start_lock.unlock();
// Do the work:
for (auto& command : list->commands)
if (r_debug_draw)
{
command->Execute(thread);
for (auto& command : list->commands)
{
thread->debug_draw_pos++;
if (thread->debug_draw_pos < debug_draw_end)
command->Execute(thread);
}
}
else
{
for (auto& command : list->commands)
{
command->Execute(thread);
}
}
// Notify main thread that we finished:

View File

@ -52,6 +52,8 @@ public:
std::shared_ptr<PolyTriangleThreadData> poly;
size_t debug_draw_pos = 0;
// Checks if a line is rendered by this thread
bool line_skipped_by_thread(int line)
{
@ -109,6 +111,8 @@ public:
// Waits for all commands to finish executing
static void WaitForWorkers();
static void ResetDebugDrawPos();
private:
DrawerThreads();
@ -132,6 +136,8 @@ private:
std::condition_variable end_condition;
size_t tasks_left = 0;
size_t debug_draw_end = 0;
DrawerThread single_core_thread;
friend class DrawerCommandQueue;

View File

@ -64,6 +64,7 @@ void PeekThreadedErrorPane();
#endif
EXTERN_CVAR(Int, r_clearbuffer)
EXTERN_CVAR(Int, r_debug_draw)
CVAR(Bool, r_scene_multithreaded, false, 0);
CVAR(Bool, r_models, false, 0);
@ -103,7 +104,7 @@ namespace swrenderer
if (r_models)
PolyTriangleDrawer::ClearBuffers(viewport->RenderTarget);
if (r_clearbuffer != 0)
if (r_clearbuffer != 0 || r_debug_draw != 0)
{
if (!viewport->RenderTarget->IsBgra())
{
@ -118,6 +119,7 @@ namespace swrenderer
for (int i = 0; i < size; i++)
dest[i] = bgracolor.d;
}
DrawerThreads::ResetDebugDrawPos();
}
RenderActorView(player->mo);