[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47602] trunk/blender: * Added OpenCL kernel for bokeh blur

Jeroen Bakker j.bakker at atmind.nl
Fri Jun 8 11:17:11 CEST 2012


Revision: 47602
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47602
Author:   jbakker
Date:     2012-06-08 09:17:07 +0000 (Fri, 08 Jun 2012)
Log Message:
-----------
 * Added OpenCL kernel for bokeh blur
 * Uncomment COM_OPENCL_ENABLED from COM_defines.h to test

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/COM_defines.h
    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_ExecutionSystem.h
    trunk/blender/source/blender/compositor/intern/COM_Node.cpp
    trunk/blender/source/blender/compositor/intern/COM_Node.h
    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_OpenCLDevice.cpp
    trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp
    trunk/blender/source/blender/compositor/nodes/COM_BlurNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_BokehBlurNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_BokehImageNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ColorCurveNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ColorMatteNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_FilterNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ImageNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_MixNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_MovieClipNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_OutputFileNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_RenderLayersNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_SplitViewerNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_TextureNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp
    trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ColorCurveOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ColorCurveOperation.h
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl
    trunk/blender/source/blender/compositor/operations/COM_OutputFileOperation.h
    trunk/blender/source/blender/compositor/operations/COM_PreviewOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_PreviewOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h
    trunk/blender/source/blender/compositor/operations/COM_WriteBufferOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_WriteBufferOperation.h
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_bokehblur.c

Added Paths:
-----------
    trunk/blender/release/datafiles/clkernelstoh.py
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h

Removed Paths:
-------------
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.cpp

Added: trunk/blender/release/datafiles/clkernelstoh.py
===================================================================
--- trunk/blender/release/datafiles/clkernelstoh.py	                        (rev 0)
+++ trunk/blender/release/datafiles/clkernelstoh.py	2012-06-08 09:17:07 UTC (rev 47602)
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2012 Blender Foundation.
+# All rights reserved.
+#
+# Contributor(s): Jeroen Bakker
+#
+# ***** END GPL LICENCE BLOCK *****
+
+# <pep8 compliant>
+
+import sys
+import os
+
+if len(sys.argv) < 2:
+    sys.stdout.write("Usage: clkernelstoh <cl_file>\n")
+    sys.exit(1)
+
+filename = sys.argv[1]
+
+try:
+    fpin = open(filename, "r")
+except:
+    sys.stdout.write("Unable to open input %s\n" % sys.argv[1])
+    sys.exit(1)
+
+if filename[0:2] == "." + os.sep:
+    filename = filename[2:]
+
+cname = filename + ".h"
+sys.stdout.write("Making H file <%s>\n" % cname)
+
+filename = filename.split("/")[-1].split("\\")[-1]
+filename = filename.replace(".", "_")
+
+try:
+    fpout = open(cname, "w")
+except:
+    sys.stdout.write("Unable to open output %s\n" % cname)
+    sys.exit(1)
+
+fpout.write("/* clkernelstoh output of file <%s> */\n\n" % filename)
+fpout.write("const char * clkernelstoh_%s = " % filename)
+
+lines = fpin.readlines()
+for line in lines:
+	fpout.write("\"")
+	fpout.write(line.rstrip())
+	fpout.write("\\n\" \\\n")
+fpout.write("\"\\0\";\n")
+
+fpin.close()
+fpout.close()


Property changes on: trunk/blender/release/datafiles/clkernelstoh.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: trunk/blender/source/blender/compositor/COM_defines.h
===================================================================
--- trunk/blender/source/blender/compositor/COM_defines.h	2012-06-08 09:15:45 UTC (rev 47601)
+++ trunk/blender/source/blender/compositor/COM_defines.h	2012-06-08 09:17:07 UTC (rev 47602)
@@ -52,12 +52,25 @@
 	COM_QUALITY_LOW    = 2
 } CompositorQuality;
 
+/**
+  * @brief Possible priority settings
+  * @ingroup Execution
+  */
+typedef enum CompositorPriority {
+	/** @brief High quality setting */
+	COM_PRIORITY_HIGH   = 2 ,
+	/** @brief Medium quality setting */
+	COM_PRIORITY_MEDIUM = 1,
+	/** @brief Low quality setting */
+	COM_PRIORITY_LOW    = 0
+} CompositorPriority;
+
 // configurable items
 
 // chunk size determination
 #define COM_PREVIEW_SIZE 140.0f
-#define COM_OPENCL_ENABLED
-#define COM_PREVIEW_ENABLED
+//#define COM_OPENCL_ENABLED
+
 // workscheduler threading models
 /**
   * COM_TM_QUEUE is a multithreaded model, which uses the BLI_thread_queue pattern. This is the default option.

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2012-06-08 09:15:45 UTC (rev 47601)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2012-06-08 09:17:07 UTC (rev 47602)
@@ -57,7 +57,7 @@
 	this->chunksFinished = 0;
 }
 
-int ExecutionGroup::getRenderPriotrity()
+CompositorPriority ExecutionGroup::getRenderPriotrity()
 {
 	return this->getOutputNodeOperation()->getRenderPriority();
 }
@@ -401,47 +401,11 @@
 	return memoryBuffers;
 }
 
-// @todo: for opencl the memory buffers size needs to be same as the needed size
-// currently this method is not called, but will be when opencl nodes are created
 MemoryBuffer *ExecutionGroup::constructConsolidatedMemoryBuffer(MemoryProxy *memoryProxy, rcti *rect)
 {
-	// find all chunks inside the rect
-	// determine minxchunk, minychunk, maxxchunk, maxychunk where x and y are chunknumbers
-	float chunkSizef = this->chunkSize;
-
-	int indexx, indexy;
-
-	const int minxchunk = floor(rect->xmin/chunkSizef);
-	const int maxxchunk = ceil((rect->xmax-1)/chunkSizef);
-	const int minychunk = floor(rect->ymin/chunkSizef);
-	const int maxychunk = ceil((rect->ymax-1)/chunkSizef);
-
-	if (maxxchunk== minxchunk+1 && maxychunk == minychunk+1) {
-		MemoryBuffer *result =memoryProxy->getBuffer();
-		return result;
-	}
-
-	rcti chunkRect;
-	chunkRect.xmin = minxchunk*this->chunkSize;
-	chunkRect.xmax = maxxchunk*this->chunkSize;
-	chunkRect.ymin = minychunk*this->chunkSize;
-	chunkRect.ymax = maxychunk*this->chunkSize;
-
-	CLAMP(chunkRect.xmin, 0, (int)this->width);
-	CLAMP(chunkRect.xmax, 0, (int)this->width);
-	CLAMP(chunkRect.ymin, 0, (int)this->height);
-	CLAMP(chunkRect.ymax, 0, (int)this->height);
-
-	MemoryBuffer *result = new MemoryBuffer(memoryProxy, &chunkRect);
-
-	for (indexx = max(minxchunk, 0); indexx<min((int)this->numberOfXChunks, maxxchunk) ; indexx++) {
-		for (indexy = max(minychunk, 0); indexy<min((int)this->numberOfYChunks, maxychunk) ; indexy++) {
-			/* int chunkNumber = indexx+indexy*this->numberOfXChunks; */ /* UNUSED */
-			MemoryBuffer *chunkBuffer = memoryProxy->getBuffer();
-			result->copyContentFrom(chunkBuffer);
-		}
-	}
-
+	MemoryBuffer* imageBuffer = memoryProxy->getBuffer();
+	MemoryBuffer* result = new MemoryBuffer(memoryProxy, rect);
+	result->copyContentFrom(imageBuffer);
 	return result;
 }
 
@@ -487,14 +451,14 @@
 
 MemoryBuffer *ExecutionGroup::allocateOutputBuffer(int chunkNumber, rcti *rect)
 {
-	MemoryBuffer *outputBuffer = NULL;
-	// output allocation is only valid when our outputoperation is a memorywriter
+	// we asume that this method is only called from complex execution groups.
 	NodeOperation * operation = this->getOutputNodeOperation();
 	if (operation->isWriteBufferOperation()) {
-/*		WriteBufferOperation *writeOperation = (WriteBufferOperation*)operation; */ /* UNUSED */
-// @todo		outputBuffer = MemoryManager::allocateMemoryBuffer(writeOperation->getMemoryProxy(), chunkNumber, rect);
+		WriteBufferOperation *writeOperation = (WriteBufferOperation*)operation;
+		MemoryBuffer *buffer = new MemoryBuffer(writeOperation->getMemoryProxy(), rect);
+		return buffer;
 	}
-	return outputBuffer;
+	return NULL;
 }
 
 
@@ -600,11 +564,6 @@
 	}
 }
 
-bool ExecutionGroup::operator ==(const ExecutionGroup & executionGroup) const
-{
-	return this->getOutputNodeOperation() == executionGroup.getOutputNodeOperation();
-}
-
 bool ExecutionGroup::isOpenCL()
 {
 	return this->openCL;

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h	2012-06-08 09:15:45 UTC (rev 47601)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h	2012-06-08 09:17:07 UTC (rev 47602)
@@ -167,14 +167,8 @@
 	  * @param operation the operation to be added
 	  */
 	bool canContainOperation(NodeOperation *operation);
-	
+		
 	/**
-	  * @brief get the Render priority of this ExecutionGroup
-	  * @see ExecutionSystem.execute
-	  */
-	int getRenderPriotrity();
-	
-	/**
 	  * @brief calculate the actual chunk size of this execution group.
 	  * @note A chunk size is an unsigned int that is both the height and width of a chunk.
 	  * @note The chunk size will not be stored in the chunkSize field. This needs to be done
@@ -396,17 +390,21 @@
 	  * @see determineChunkSize()
 	  */
 	void determineChunkRect(rcti *rect, const unsigned int chunkNumber) const;
-	
-	
-		bool operator ==(const ExecutionGroup &executionGroup) const;
-	
-		/**
+
+	/**
 	  * @brief can this ExecutionGroup be scheduled on an OpenCLDevice
 	  * @see WorkScheduler.schedule
 	  */
 	bool isOpenCL();
-	
+
 	void setChunksize(int chunksize) {this->chunkSize = chunksize;}
+
+	/**
+	  * @brief get the Render priority of this ExecutionGroup
+	  * @see ExecutionSystem.execute
+	  */
+	CompositorPriority getRenderPriotrity();
+	
 };
 
 #endif

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2012-06-08 09:15:45 UTC (rev 47601)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2012-06-08 09:17:07 UTC (rev 47602)
@@ -127,21 +127,10 @@
 
 	WorkScheduler::start(this->context);
 
+	executeGroups(COM_PRIORITY_HIGH);
+	executeGroups(COM_PRIORITY_MEDIUM);
+	executeGroups(COM_PRIORITY_LOW);
 
-	vector<ExecutionGroup*> executionGroups;
-	this->findOutputExecutionGroup(&executionGroups);
-
-	/* start execution of the ExecutionGroups based on priority of their output node */
-	for (int priority = 9 ; priority>=0 ; priority--) {
-		for (index = 0 ; index < executionGroups.size(); index ++) {
-			ExecutionGroup *group = executionGroups[index];
-			NodeOperation *output = group->getOutputNodeOperation();
-			if (output->getRenderPriority() == priority) {
-				group->execute(this);
-			}
-		}
-	}
-
 	WorkScheduler::finish();
 	WorkScheduler::stop();
 
@@ -155,6 +144,18 @@
 	}
 }
 
+void ExecutionSystem::executeGroups(CompositorPriority priority)
+{
+	int index;
+	vector<ExecutionGroup*> executionGroups;
+	this->findOutputExecutionGroup(&executionGroups, priority);
+
+	for (index = 0 ; index < executionGroups.size(); index ++) {
+		ExecutionGroup *group = executionGroups[index];
+		group->execute(this);
+	}
+}
+
 void ExecutionSystem::addOperation(NodeOperation *operation)
 {
 	ExecutionSystemHelper::addOperation(this->operations, operation);
@@ -304,6 +305,17 @@
 	}
 }
 
+void ExecutionSystem::findOutputExecutionGroup(vector<ExecutionGroup*> *result, CompositorPriority priority) const
+{
+	unsigned int index;
+	for (index = 0 ; index < this->groups.size() ; index ++) {
+		ExecutionGroup *group = this->groups[index];
+		if (group->isOutputExecutionGroup() && group->getRenderPriotrity() == priority) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list