[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47826] trunk/blender/source/blender/ compositor: * optimized threading

Jeroen Bakker j.bakker at atmind.nl
Wed Jun 13 14:35:08 CEST 2012


Revision: 47826
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47826
Author:   jbakker
Date:     2012-06-13 12:34:56 +0000 (Wed, 13 Jun 2012)
Log Message:
-----------
 * optimized threading
 * break out with glare node
 * Added OpenCL kernels compatible with AMD still need some testing.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/CMakeLists.txt
    trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
    trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h
    trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
    trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
    trunk/blender/source/blender/compositor/intern/COM_NodeOperation.cpp
    trunk/blender/source/blender/compositor/intern/COM_NodeOperation.h
    trunk/blender/source/blender/compositor/intern/COM_compositor.cpp
    trunk/blender/source/blender/compositor/nodes/COM_DilateErodeNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_MuteNode.cpp
    trunk/blender/source/blender/compositor/operations/COM_AntiAliasOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_CalculateMeanOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h
    trunk/blender/source/blender/compositor/operations/COM_DilateErodeOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_DilateErodeOperation.h
    trunk/blender/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GlareBaseOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GlareBaseOperation.h
    trunk/blender/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GlareSimpleStarOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MaskOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MultilayerImageOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_NormalizeOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h
    trunk/blender/source/blender/compositor/operations/COM_OutputFileOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_PreviewOperation.h
    trunk/blender/source/blender/compositor/operations/COM_TonemapOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_VectorBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_WriteBufferOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_WriteBufferOperation.h

Added Paths:
-----------
    trunk/blender/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp
    trunk/blender/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.h

Modified: trunk/blender/source/blender/compositor/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/compositor/CMakeLists.txt	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/CMakeLists.txt	2012-06-13 12:34:56 UTC (rev 47826)
@@ -97,6 +97,9 @@
 	intern/COM_CompositorContext.h
 	intern/COM_ChannelInfo.cpp
 	intern/COM_ChannelInfo.h
+	intern/COM_SingleThreadedNodeOperation.cpp
+	intern/COM_SingleThreadedNodeOperation.h
+
 	operations/COM_QualityStepHelper.h
 	operations/COM_QualityStepHelper.cpp
 

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2012-06-13 12:34:56 UTC (rev 47826)
@@ -54,6 +54,7 @@
 	this->numberOfChunks = 0;
 	this->initialized = false;
 	this->openCL = false;
+	this->singleThreaded = false;
 	this->chunksFinished = 0;
 }
 
@@ -100,6 +101,7 @@
 		if (!operation->isBufferOperation()) {
 			this->complex = operation->isComplex();
 			this->openCL = operation->isOpenCL();
+			this->singleThreaded = operation->isSingleThreaded();
 			this->initialized = true;
 		}
 		this->operations.push_back(operation);
@@ -191,10 +193,17 @@
 
 void ExecutionGroup::determineNumberOfChunks()
 {
-	const float chunkSizef = this->chunkSize;
-	this->numberOfXChunks = ceil(this->width / chunkSizef);
-	this->numberOfYChunks = ceil(this->height / chunkSizef);
-	this->numberOfChunks = this->numberOfXChunks * this->numberOfYChunks;
+	if (singleThreaded) {
+		this->numberOfXChunks = 1;
+		this->numberOfYChunks = 1;
+		this->numberOfChunks = 1;
+	} 
+	else {
+		const float chunkSizef = this->chunkSize;
+		this->numberOfXChunks = ceil(this->width / chunkSizef);
+		this->numberOfYChunks = ceil(this->height / chunkSizef);
+		this->numberOfChunks = this->numberOfXChunks * this->numberOfYChunks;
+	}
 }
 
 /**
@@ -435,9 +444,14 @@
 
 inline void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int xChunk, const unsigned int yChunk ) const
 {
-	const unsigned int minx = xChunk * chunkSize;
-	const unsigned int miny = yChunk * chunkSize;
-	BLI_init_rcti(rect, minx, min(minx + this->chunkSize, this->width), miny, min(miny + this->chunkSize, this->height));
+	if (singleThreaded) {
+		BLI_init_rcti(rect, 0, this->width, 0, this->height);
+	}
+	else {
+		const unsigned int minx = xChunk * chunkSize;
+		const unsigned int miny = yChunk * chunkSize;
+		BLI_init_rcti(rect, minx, min(minx + this->chunkSize, this->width), miny, min(miny + this->chunkSize, this->height));
+	}
 }
 
 void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int chunkNumber) const
@@ -462,6 +476,9 @@
 
 bool ExecutionGroup::scheduleAreaWhenPossible(ExecutionSystem * graph, rcti *area)
 {
+	if (singleThreaded) {
+		return scheduleChunkWhenPossible(graph, 0, 0);
+	}
 	// find all chunks inside the rect
 	// determine minxchunk, minychunk, maxxchunk, maxychunk where x and y are chunknumbers
 

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h	2012-06-13 12:34:56 UTC (rev 47826)
@@ -63,10 +63,6 @@
 class ExecutionGroup {
 private:
 	// fields
-	/**
-	  * @brief unique identifier of this node.
-	  */
-	string id;
 	
 	/**
 	  * @brief list of operations in this ExecutionGroup
@@ -121,6 +117,11 @@
 	bool openCL;
 	
 	/**
+	 * @brief Is this Execution group SingleThreaded
+	 */
+	bool singleThreaded;
+	
+	/**
 	  * @brief what is the maximum number field of all ReadBufferOperation in this ExecutionGroup.
 	  * @note this is used to construct the MemoryBuffers that will be passed during execution.
 	  */
@@ -233,18 +234,7 @@
 public:
 	// constructors
 	ExecutionGroup();
-	
-	/**
-	  * @brief set the id of this ExecutionGroup
-	  * @param id
-	  */
-	void setId(string id) {this->id = id;}
-	
-	/**
-	  * @brief return the id of this ExecutionGroup
-	  */
-	const string getId() const {return this->id;}
-	
+		
 	// methods
 	/**
 	  * @brief check to see if a NodeOperation is already inside this execution group

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2012-06-13 12:34:56 UTC (rev 47826)
@@ -124,6 +124,7 @@
 
 	for (index = 0 ; index < this->operations.size() ; index ++) {
 		NodeOperation * operation = this->operations[index];
+		operation->setbNodeTree(this->context.getbNodeTree());
 		operation->initExecution();
 	}
 	for (index = 0 ; index < this->groups.size() ; index ++) {
@@ -153,7 +154,7 @@
 
 void ExecutionSystem::executeGroups(CompositorPriority priority)
 {
-	int index;
+	unsigned int index;
 	vector<ExecutionGroup*> executionGroups;
 	this->findOutputExecutionGroup(&executionGroups, priority);
 
@@ -166,6 +167,7 @@
 void ExecutionSystem::addOperation(NodeOperation *operation)
 {
 	ExecutionSystemHelper::addOperation(this->operations, operation);
+//	operation->setBTree
 }
 
 void ExecutionSystem::addReadWriteBufferOperations(NodeOperation *operation)

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp	2012-06-13 12:34:56 UTC (rev 47826)
@@ -65,7 +65,7 @@
 	}
 
 	/* Expand group nodes */
-	for (int i=nodes_start; i < nodes.size(); ++i) {
+	for (unsigned int i=nodes_start; i < nodes.size(); ++i) {
 		Node *execnode = nodes[i];
 		if (execnode->isGroupNode()) {
 			GroupNode * groupNode = (GroupNode*)execnode;

Modified: trunk/blender/source/blender/compositor/intern/COM_NodeOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_NodeOperation.cpp	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/intern/COM_NodeOperation.cpp	2012-06-13 12:34:56 UTC (rev 47826)
@@ -34,6 +34,7 @@
 	this->width = 0;
 	this->height = 0;
 	this->openCL = false;
+	this->btree = NULL;
 }
 
 void NodeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
@@ -74,10 +75,22 @@
 {
 	BLI_mutex_init(&mutex);
 }
+
+void NodeOperation::lockMutex()
+{
+	BLI_mutex_lock(&mutex);
+}
+
+void NodeOperation::unlockMutex()
+{
+	BLI_mutex_unlock(&mutex);
+}
+
 void NodeOperation::deinitMutex()
 {
 	BLI_mutex_end(&mutex);
 }
+
 void NodeOperation::deinitExecution()
 {
 }
@@ -196,14 +209,15 @@
 	size_t size[2];
 	cl_int2 offset;
 	
-	for (offsety = 0 ; offsety < height; offsety+=localSize) {
+	bool breaked = false;
+	for (offsety = 0 ; offsety < height && (!breaked); offsety+=localSize) {
 		offset[1] = offsety;
 		if (offsety+localSize < height) {
 			size[1] = localSize;
 		} else {
 			size[1] = height - offsety;
 		}
-		for (offsetx = 0 ; offsetx < width ; offsetx+=localSize) {
+		for (offsetx = 0 ; offsetx < width && (!breaked) ; offsetx+=localSize) {
 			if (offsetx+localSize < width) {
 				size[0] = localSize;
 			} else {
@@ -216,6 +230,9 @@
 			error = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, size, 0, 0, 0, NULL);
 			if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
 			clFlush(queue);
+			if (isBreaked()) {
+				breaked = false;
+			}
 		}
 	}
 }

Modified: trunk/blender/source/blender/compositor/intern/COM_NodeOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_NodeOperation.h	2012-06-13 11:44:48 UTC (rev 47825)
+++ trunk/blender/source/blender/compositor/intern/COM_NodeOperation.h	2012-06-13 12:34:56 UTC (rev 47826)
@@ -77,6 +77,11 @@
 	  * @see NodeOperation.getMutex retrieve a pointer to this mutex.
 	  */
 	ThreadMutex mutex;
+	
+	/**
+	 * @brief reference to the editing bNodeTree only used for break callback
+	 */
+	const bNodeTree *btree;
 
 public:
 	/**
@@ -119,9 +124,10 @@
 	  * for all other operations this will result in false.
 	  */
 	virtual int isBufferOperation() {return false;}
+	virtual int isSingleThreaded() {return false;}
 
+	void setbNodeTree(const bNodeTree * tree) {this->btree = tree;}
 	virtual void initExecution();
-	void initMutex();
 	
 	/**
 	  * @brief when a chunk is executed by a CPUDevice, this method is called
@@ -161,7 +167,6 @@
 	  */
 	virtual void executeOpenCL(cl_context context,cl_program program, cl_command_queue queue, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer** inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) {}
 	virtual void deinitExecution();
-	void deinitMutex();
 
 	bool isResolutionSet() {
 		return this->width != 0 && height != 0;
@@ -236,6 +241,11 @@
 	
 	virtual bool isViewerOperation() {return false;}
 	virtual bool isPreviewOperation() {return false;}
+	
+	inline bool isBreaked() {
+		return btree->test_break(btree->tbh);
+	}
+
 protected:
 	NodeOperation();
 
@@ -244,7 +254,11 @@
 	SocketReader *getInputSocketReader(unsigned int inputSocketindex);
 	NodeOperation *getInputOperation(unsigned int inputSocketindex);
 
-	inline ThreadMutex *getMutex() {return &this->mutex;}
+	void deinitMutex();
+	void initMutex();
+	void lockMutex();
+	void unlockMutex();
+	
 
 	/**
 	  * @brief set whether this operation is complex
@@ -264,7 +278,7 @@
 	static void COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, cl_mem clOutputMemoryBuffer);
 	void COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex);
 	static void COM_clEnqueueRange(cl_command_queue queue, cl_kernel kernel, MemoryBuffer* outputMemoryBuffer);
-	static void COM_clEnqueueRange(cl_command_queue queue, cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list