mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-16 09:31:14 +00:00
- add support for specifying the exact thread count to r_multithreaded and r_scene_multithreaded
This commit is contained in:
parent
90ee8a6033
commit
7144ac6897
5 changed files with 33 additions and 20 deletions
|
@ -44,7 +44,7 @@
|
|||
void PeekThreadedErrorPane();
|
||||
#endif
|
||||
|
||||
EXTERN_CVAR(Bool, r_scene_multithreaded);
|
||||
EXTERN_CVAR(Int, r_scene_multithreaded);
|
||||
|
||||
PolyRenderThread::PolyRenderThread(int threadIndex) : MainThread(threadIndex == 0), ThreadIndex(threadIndex)
|
||||
{
|
||||
|
@ -151,8 +151,10 @@ void PolyRenderThreads::RenderThreadSlices(int totalcount, std::function<void(Po
|
|||
if (numThreads == 0)
|
||||
numThreads = 4;
|
||||
|
||||
if (!r_scene_multithreaded || !r_multithreaded)
|
||||
if (r_scene_multithreaded == 0 || r_multithreaded == 0)
|
||||
numThreads = 1;
|
||||
else if (r_scene_multithreaded != 1)
|
||||
numThreads = r_scene_multithreaded;
|
||||
|
||||
if (numThreads != (int)Threads.size())
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
struct FSWColormap;
|
||||
struct FLightNode;
|
||||
|
||||
EXTERN_CVAR(Bool, r_multithreaded);
|
||||
EXTERN_CVAR(Int, r_multithreaded);
|
||||
EXTERN_CVAR(Bool, r_magfilter);
|
||||
EXTERN_CVAR(Bool, r_minfilter);
|
||||
EXTERN_CVAR(Bool, r_mipmap);
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
void PeekThreadedErrorPane();
|
||||
#endif
|
||||
|
||||
CVAR(Bool, r_multithreaded, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
CVAR(Int, r_multithreaded, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
CVAR(Int, r_debug_draw, 0, 0);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -66,10 +66,11 @@ void DrawerThreads::Execute(DrawerCommandQueuePtr commands)
|
|||
|
||||
auto queue = Instance();
|
||||
|
||||
queue->StartThreads();
|
||||
|
||||
// Add to queue and awaken worker threads
|
||||
std::unique_lock<std::mutex> start_lock(queue->start_mutex);
|
||||
std::unique_lock<std::mutex> end_lock(queue->end_mutex);
|
||||
queue->StartThreads();
|
||||
queue->active_commands.push_back(commands);
|
||||
queue->tasks_left += queue->threads.size();
|
||||
end_lock.unlock();
|
||||
|
@ -171,22 +172,31 @@ void DrawerThreads::WorkerMain(DrawerThread *thread)
|
|||
|
||||
void DrawerThreads::StartThreads()
|
||||
{
|
||||
if (!threads.empty())
|
||||
return;
|
||||
std::unique_lock<std::mutex> lock(threads_mutex);
|
||||
|
||||
int num_threads = std::thread::hardware_concurrency();
|
||||
if (num_threads == 0)
|
||||
num_threads = 4;
|
||||
|
||||
threads.resize(num_threads);
|
||||
if (r_multithreaded == 0)
|
||||
num_threads = 1;
|
||||
else if (r_multithreaded != 1)
|
||||
num_threads = r_multithreaded;
|
||||
|
||||
for (int i = 0; i < num_threads; i++)
|
||||
if (num_threads != (int)threads.size())
|
||||
{
|
||||
DrawerThreads *queue = this;
|
||||
DrawerThread *thread = &threads[i];
|
||||
thread->core = i;
|
||||
thread->num_cores = num_threads;
|
||||
thread->thread = std::thread([=]() { queue->WorkerMain(thread); });
|
||||
StopThreads();
|
||||
|
||||
threads.resize(num_threads);
|
||||
|
||||
for (int i = 0; i < num_threads; i++)
|
||||
{
|
||||
DrawerThreads *queue = this;
|
||||
DrawerThread *thread = &threads[i];
|
||||
thread->core = i;
|
||||
thread->num_cores = num_threads;
|
||||
thread->thread = std::thread([=]() { queue->WorkerMain(thread); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <condition_variable>
|
||||
|
||||
// Use multiple threads when drawing
|
||||
EXTERN_CVAR(Bool, r_multithreaded)
|
||||
EXTERN_CVAR(Int, r_multithreaded)
|
||||
|
||||
class PolyTriangleThreadData;
|
||||
|
||||
|
@ -133,6 +133,7 @@ private:
|
|||
|
||||
static DrawerThreads *Instance();
|
||||
|
||||
std::mutex threads_mutex;
|
||||
std::vector<DrawerThread> threads;
|
||||
|
||||
std::mutex start_mutex;
|
||||
|
@ -165,7 +166,7 @@ public:
|
|||
void Push(Types &&... args)
|
||||
{
|
||||
DrawerThreads *threads = DrawerThreads::Instance();
|
||||
if (ThreadedRender && r_multithreaded)
|
||||
if (r_multithreaded != 0)
|
||||
{
|
||||
void *ptr = AllocMemory(sizeof(T));
|
||||
T *command = new (ptr)T(std::forward<Types>(args)...);
|
||||
|
@ -178,8 +179,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool ThreadedRender = true;
|
||||
|
||||
private:
|
||||
// Allocate memory valid for the duration of a command execution
|
||||
void *AllocMemory(size_t size);
|
||||
|
|
|
@ -67,7 +67,7 @@ EXTERN_CVAR(Bool, r_shadercolormaps)
|
|||
EXTERN_CVAR(Int, r_clearbuffer)
|
||||
EXTERN_CVAR(Int, r_debug_draw)
|
||||
|
||||
CVAR(Bool, r_scene_multithreaded, false, 0);
|
||||
CVAR(Int, r_scene_multithreaded, 0, 0);
|
||||
CVAR(Bool, r_models, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
|
||||
bool r_modelscene = false;
|
||||
|
@ -218,8 +218,10 @@ namespace swrenderer
|
|||
if (numThreads == 0)
|
||||
numThreads = 4;
|
||||
|
||||
if (!r_scene_multithreaded || !r_multithreaded)
|
||||
if (r_scene_multithreaded == 0 || r_multithreaded == 0)
|
||||
numThreads = 1;
|
||||
else if (r_scene_multithreaded != 1)
|
||||
numThreads = r_scene_multithreaded;
|
||||
|
||||
if (numThreads != (int)Threads.size())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue