From c9fd52340ec5689780023d6f7d10f4b0c4d56377 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 10 Jun 2018 13:35:15 +0200 Subject: [PATCH] - add GroupMemoryBarrierCommand --- src/swrenderer/drawers/r_thread.cpp | 12 ++++++++++++ src/swrenderer/drawers/r_thread.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/swrenderer/drawers/r_thread.cpp b/src/swrenderer/drawers/r_thread.cpp index 657960b174..9aa148a6d8 100644 --- a/src/swrenderer/drawers/r_thread.cpp +++ b/src/swrenderer/drawers/r_thread.cpp @@ -203,6 +203,8 @@ void DrawerThreads::StopThreads() shutdown_flag = false; } +///////////////////////////////////////////////////////////////////////////// + DrawerCommandQueue::DrawerCommandQueue(RenderMemory *frameMemory) : FrameMemory(frameMemory) { } @@ -211,3 +213,13 @@ void *DrawerCommandQueue::AllocMemory(size_t size) { return FrameMemory->AllocMemory((int)size); } + +///////////////////////////////////////////////////////////////////////////// + +void GroupMemoryBarrierCommand::Execute(DrawerThread *thread) +{ + std::unique_lock lock(mutex); + count++; + condition.notify_all(); + condition.wait(lock, [&]() { return count >= thread->num_cores; }); +} diff --git a/src/swrenderer/drawers/r_thread.h b/src/swrenderer/drawers/r_thread.h index f75cc84362..76e6510384 100644 --- a/src/swrenderer/drawers/r_thread.h +++ b/src/swrenderer/drawers/r_thread.h @@ -97,6 +97,18 @@ public: virtual void Execute(DrawerThread *thread) = 0; }; +// Wait for all worker threads before executing next command +class GroupMemoryBarrierCommand : public DrawerCommand +{ +public: + void Execute(DrawerThread *thread); + +private: + std::mutex mutex; + std::condition_variable condition; + size_t count = 0; +}; + class DrawerCommandQueue; typedef std::shared_ptr DrawerCommandQueuePtr;