Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-03-03 13:59:20 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-03-03 14:02:31 +0300
commit8c113a95e3536dfa0be37c9e2e924ea8172bb613 (patch)
treefc71fffa34bc552168f79efccd5bd02b14700556 /source/blender/compositor
parentba7eb0c7b9d93987173780d5b819c7f2ec79b96e (diff)
Make texture node threaded
Quite trivial idea -- just pass tread ID to the texture sampling function. Implemented as a TLS to avoid passing huge amount of extra contexts around. Should be working on all platforms, but compilation test is required. Reviewers: juicyfruit, campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D1831
Diffstat (limited to 'source/blender/compositor')
-rw-r--r--source/blender/compositor/intern/COM_CPUDevice.cpp6
-rw-r--r--source/blender/compositor/intern/COM_CPUDevice.h7
-rw-r--r--source/blender/compositor/intern/COM_WorkScheduler.cpp22
-rw-r--r--source/blender/compositor/intern/COM_WorkScheduler.h2
-rw-r--r--source/blender/compositor/operations/COM_TextureOperation.cpp25
-rw-r--r--source/blender/compositor/operations/COM_TextureOperation.h4
6 files changed, 46 insertions, 20 deletions
diff --git a/source/blender/compositor/intern/COM_CPUDevice.cpp b/source/blender/compositor/intern/COM_CPUDevice.cpp
index c7c3f7769fe..a5824ec5248 100644
--- a/source/blender/compositor/intern/COM_CPUDevice.cpp
+++ b/source/blender/compositor/intern/COM_CPUDevice.cpp
@@ -22,6 +22,12 @@
#include "COM_CPUDevice.h"
+CPUDevice::CPUDevice(int thread_id)
+ : Device(),
+ m_thread_id(thread_id)
+{
+}
+
void CPUDevice::execute(WorkPackage *work)
{
const unsigned int chunkNumber = work->getChunkNumber();
diff --git a/source/blender/compositor/intern/COM_CPUDevice.h b/source/blender/compositor/intern/COM_CPUDevice.h
index 3dc8fff66a3..d12666593d4 100644
--- a/source/blender/compositor/intern/COM_CPUDevice.h
+++ b/source/blender/compositor/intern/COM_CPUDevice.h
@@ -31,11 +31,18 @@
*/
class CPUDevice : public Device {
public:
+ CPUDevice(int thread_id);
+
/**
* @brief execute a WorkPackage
* @param work the WorkPackage to execute
*/
void execute(WorkPackage *work);
+
+ int thread_id() { return m_thread_id; }
+
+protected:
+ int m_thread_id;
};
#endif
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp
index fc6ea1299cf..4c85f11f655 100644
--- a/source/blender/compositor/intern/COM_WorkScheduler.cpp
+++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp
@@ -50,7 +50,8 @@
/// @brief list of all CPUDevices. for every hardware thread an instance of CPUDevice is created
-static vector<CPUDevice *> g_cpudevices;
+static vector<CPUDevice*> g_cpudevices;
+static ThreadLocal(CPUDevice*) g_thread_device;
#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
/// @brief list of all thread for every CPUDevice in cpudevices a thread exists
@@ -153,9 +154,9 @@ int COM_isHighlightedbNode(bNode *bnode)
#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
void *WorkScheduler::thread_execute_cpu(void *data)
{
- Device *device = (Device *)data;
+ CPUDevice *device = (CPUDevice *)data;
WorkPackage *work;
-
+ BLI_thread_local_set(g_thread_device, device);
while ((work = (WorkPackage *)BLI_thread_queue_pop(g_cpuqueue))) {
HIGHLIGHT(work);
device->execute(work);
@@ -310,18 +311,20 @@ void WorkScheduler::initialize(bool use_opencl, int num_cpu_threads)
device->deinitialize();
delete device;
}
-
+ if (g_cpuInitialized) {
+ BLI_thread_local_delete(g_thread_device);
+ }
g_cpuInitialized = false;
}
/* initialize CPU threads */
if (!g_cpuInitialized) {
for (int index = 0; index < num_cpu_threads; index++) {
- CPUDevice *device = new CPUDevice();
+ CPUDevice *device = new CPUDevice(index);
device->initialize();
g_cpudevices.push_back(device);
}
-
+ BLI_thread_local_create(g_thread_device);
g_cpuInitialized = true;
}
@@ -407,7 +410,7 @@ void WorkScheduler::deinitialize()
device->deinitialize();
delete device;
}
-
+ BLI_thread_local_delete(g_thread_device);
g_cpuInitialized = false;
}
@@ -450,3 +453,8 @@ void WorkScheduler::deinitialize()
}
}
+int WorkScheduler::current_thread_id()
+{
+ CPUDevice *device = (CPUDevice *)BLI_thread_local_get(g_thread_device);
+ return device->thread_id();
+}
diff --git a/source/blender/compositor/intern/COM_WorkScheduler.h b/source/blender/compositor/intern/COM_WorkScheduler.h
index 27afdf6efd0..67d3fc87ce1 100644
--- a/source/blender/compositor/intern/COM_WorkScheduler.h
+++ b/source/blender/compositor/intern/COM_WorkScheduler.h
@@ -113,6 +113,8 @@ public:
*/
static bool hasGPUDevices();
+ static int current_thread_id();
+
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:WorkScheduler")
#endif
diff --git a/source/blender/compositor/operations/COM_TextureOperation.cpp b/source/blender/compositor/operations/COM_TextureOperation.cpp
index 7d1d24a9747..665bffc2c1c 100644
--- a/source/blender/compositor/operations/COM_TextureOperation.cpp
+++ b/source/blender/compositor/operations/COM_TextureOperation.cpp
@@ -21,6 +21,7 @@
*/
#include "COM_TextureOperation.h"
+#include "COM_WorkScheduler.h"
#include "BLI_listbase.h"
#include "BLI_threads.h"
@@ -30,9 +31,7 @@ extern "C" {
#include "BKE_node.h"
}
-static ThreadMutex mutex_lock = BLI_MUTEX_INITIALIZER;
-
-TextureBaseOperation::TextureBaseOperation() : SingleThreadedOperation()
+TextureBaseOperation::TextureBaseOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_VECTOR); //offset
this->addInputSocket(COM_DT_VECTOR); //size
@@ -63,7 +62,7 @@ void TextureBaseOperation::initExecution()
{
ntreeTexBeginExecTree(this->m_texture->nodetree);
}
- SingleThreadedOperation::initExecution();
+ NodeOperation::initExecution();
}
void TextureBaseOperation::deinitExecution()
{
@@ -78,7 +77,7 @@ void TextureBaseOperation::deinitExecution()
{
ntreeTexEndExecTree(this->m_texture->nodetree->execdata);
}
- SingleThreadedOperation::deinitExecution();
+ NodeOperation::deinitExecution();
}
void TextureBaseOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
@@ -121,12 +120,16 @@ void TextureBaseOperation::executePixelSampled(float output[4], float x, float y
vec[1] = textureSize[1] * (v + textureOffset[1]);
vec[2] = textureSize[2] * textureOffset[2];
- /* TODO(sergey): Need to pass thread ID to the multitex code,
- * then we can avoid having mutex here.
- */
- BLI_mutex_lock(&mutex_lock);
- retval = multitex_ext(this->m_texture, vec, NULL, NULL, 0, &texres, m_pool, m_sceneColorManage, false);
- BLI_mutex_unlock(&mutex_lock);
+ const int thread_id = WorkScheduler::current_thread_id();
+ retval = multitex_ext(this->m_texture,
+ vec,
+ NULL, NULL,
+ 0,
+ &texres,
+ thread_id,
+ m_pool,
+ m_sceneColorManage,
+ false);
if (texres.talpha)
output[3] = texres.ta;
diff --git a/source/blender/compositor/operations/COM_TextureOperation.h b/source/blender/compositor/operations/COM_TextureOperation.h
index 47ef40882c5..4cc203b54a2 100644
--- a/source/blender/compositor/operations/COM_TextureOperation.h
+++ b/source/blender/compositor/operations/COM_TextureOperation.h
@@ -24,7 +24,7 @@
#ifndef _COM_TextureOperation_h
#define _COM_TextureOperation_h
-#include "COM_SingleThreadedOperation.h"
+#include "COM_NodeOperation.h"
#include "DNA_texture_types.h"
#include "BLI_listbase.h"
extern "C" {
@@ -39,7 +39,7 @@ extern "C" {
*
* @todo: rename to operation.
*/
-class TextureBaseOperation : public SingleThreadedOperation {
+class TextureBaseOperation : public NodeOperation {
private:
Tex *m_texture;
const RenderData *m_rd;