- 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 #endif
CVAR(Bool, r_multithreaded, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); 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(); 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() void DrawerThreads::WaitForWorkers()
{ {
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -124,10 +142,22 @@ void DrawerThreads::WorkerMain(DrawerThread *thread)
start_lock.unlock(); start_lock.unlock();
// Do the work: // Do the work:
if (r_debug_draw)
{
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) for (auto& command : list->commands)
{ {
command->Execute(thread); command->Execute(thread);
} }
}
// Notify main thread that we finished: // Notify main thread that we finished:
std::unique_lock<std::mutex> end_lock(end_mutex); std::unique_lock<std::mutex> end_lock(end_mutex);

View file

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

View file

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