Two pass execution:
authorJeroen Bakker <j.bakker@atmind.nl>
Wed, 4 Jul 2012 11:39:28 +0000 (11:39 +0000)
committerJeroen Bakker <j.bakker@atmind.nl>
Wed, 4 Jul 2012 11:39:28 +0000 (11:39 +0000)
1. first pass only fast nodes are calculated and only to the active
viewer node
2. second pass all nodes to all outputs

Temp disabled highlights because of random crashes.

13 files changed:
release/scripts/startup/bl_ui/space_node.py
source/blender/compositor/intern/COM_CompositorContext.cpp
source/blender/compositor/intern/COM_CompositorContext.h
source/blender/compositor/intern/COM_Converter.cpp
source/blender/compositor/intern/COM_Converter.h
source/blender/compositor/intern/COM_ExecutionSystem.cpp
source/blender/compositor/intern/COM_ExecutionSystem.h
source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
source/blender/compositor/intern/COM_ExecutionSystemHelper.h
source/blender/compositor/intern/COM_compositor.cpp
source/blender/compositor/operations/COM_WriteBufferOperation.cpp
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c

index e29500858ee2e8e1460cc4e46fdd61fa0f38da3c..40c7b63224772c79c46e4f44c8f665e92465ecf0 100644 (file)
@@ -233,8 +233,9 @@ class NODE_PT_quality(bpy.types.Panel):
         layout.prop(tree, "edit_quality", text="Edit")
         layout.prop(tree, "chunk_size")
         layout.prop(tree, "use_opencl")
+        layout.prop(tree, "two_pass")
         layout.prop(snode, "show_highlight")
-
+        
 
 class NODE_MT_node_color_presets(Menu):
     """Predefined node color"""
index 56335630b8065890e5621929251adaa3cc7f927c..fbdb4cd6b2810870b6db5d57aea4d4d2a9b2fb03 100644 (file)
@@ -30,6 +30,7 @@ CompositorContext::CompositorContext()
        this->m_quality = COM_QUALITY_HIGH;
        this->m_hasActiveOpenCLDevices = false;
        this->m_activegNode = NULL;
+       this->m_fastCalculation = false;
 }
 
 const int CompositorContext::getFramenumber() const
index 49acda811f109be7d757bd835e1c3b07bdd74c94..2f6abf399850590de5230073097dd8bb710b5f92 100644 (file)
@@ -73,6 +73,11 @@ private:
         * @brief does this system have active opencl devices?
         */
        bool m_hasActiveOpenCLDevices;
+       
+       /**
+        * @brief Skip slow nodes
+        */
+       bool m_fastCalculation;
 
 public:
        /**
@@ -148,6 +153,9 @@ public:
        int getChunksize() { return this->getbNodeTree()->chunksize; }
        
        const int isColorManaged() const;
+       
+       void setFastCalculation(bool fastCalculation) {this->m_fastCalculation = fastCalculation;}
+       bool isFastCalculation() {return this->m_fastCalculation;}
 };
 
 
index 38c514d8e995eba670e6f78b96549fbe260cb217..05fcfb33c51f48e83582aa460ca6d0692d0c4aed 100644 (file)
 #include "COM_ViewerNode.h"
 #include "COM_ZCombineNode.h"
 
-Node *Converter::convert(bNode *b_node)
+Node *Converter::convert(bNode *b_node, bool fast)
 {
        Node *node;
 
@@ -125,6 +125,22 @@ Node *Converter::convert(bNode *b_node)
                node = new MuteNode(b_node);
                return node;
        }
+       if (fast) {
+               if (b_node->type == CMP_NODE_BLUR ||
+                       b_node->type == CMP_NODE_VECBLUR ||
+                       b_node->type == CMP_NODE_BILATERALBLUR ||
+                       b_node->type == CMP_NODE_DEFOCUS ||
+                       b_node->type == CMP_NODE_BOKEHBLUR ||
+                       b_node->type == CMP_NODE_GLARE ||
+                       b_node->type == CMP_NODE_DBLUR ||
+                       b_node->type == CMP_NODE_MOVIEDISTORTION ||
+                       b_node->type == CMP_NODE_LENSDIST ||
+                       b_node->type == CMP_NODE_DOUBLEEDGEMASK ||
+                       b_node->type == CMP_NODE_DILATEERODE) 
+               {
+                       return new MuteNode(b_node);
+               }
+       }
 
        switch (b_node->type) {
                case CMP_NODE_COMPOSITE:
index dbe98871c506cddcc5b52480ac54138bc93019ef..15bda0839fabd6d63ececd919edd8101d1cf025d 100644 (file)
@@ -42,7 +42,7 @@ public:
         * @see Node
         * @see MuteNode
         */
-       static Node *convert(bNode *b_node);
+       static Node *convert(bNode *b_node, bool fast);
        
        /**
         * @brief This method will add a datetype conversion rule when the to-socket does not support the from-socket actual data type.
index 23e243187d52a69f41b296e8ddcf88c3c9eef6c1..ff841092848a30887a2944c444eac4057794a43e 100644 (file)
 #include "MEM_guardedalloc.h"
 #endif
 
-ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering)
+ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation)
 {
        this->m_context.setbNodeTree(editingtree);
+       this->m_context.setFastCalculation(fastcalculation);
        bNode *gnode;
        for (gnode = (bNode *)editingtree->nodes.first; gnode; gnode = (bNode *)gnode->next) {
                if (gnode->type == NODE_GROUP && gnode->typeinfo->group_edit_get(gnode)) {
@@ -137,8 +138,10 @@ void ExecutionSystem::execute()
        WorkScheduler::start(this->m_context);
 
        executeGroups(COM_PRIORITY_HIGH);
-       executeGroups(COM_PRIORITY_MEDIUM);
-       executeGroups(COM_PRIORITY_LOW);
+       if (!this->getContext().isFastCalculation()) {
+               executeGroups(COM_PRIORITY_MEDIUM);
+               executeGroups(COM_PRIORITY_LOW);
+       }
 
        WorkScheduler::finish();
        WorkScheduler::stop();
index e51bd7f3026b0c5915c868620d437889f7b421f0..209358ec78603213ff4b9c703066e5d190b3b037 100644 (file)
@@ -156,7 +156,7 @@ public:
         * @param editingtree [bNodeTree*]
         * @param rendering [true false]
         */
-       ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering);
+       ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation);
 
        /**
         * Destructor
index 0f6ba1f4ac9fbeeb4b14e4856a632f18a96a6e88..0abf7efdcfa8591c36b452776eb86fccfe84bd5f 100644 (file)
@@ -49,7 +49,7 @@ void ExecutionSystemHelper::addbNodeTree(ExecutionSystem &system, int nodes_star
        /* add all nodes of the tree to the node list */
        bNode *node = (bNode *)tree->nodes.first;
        while (node != NULL) {
-               addNode(nodes, node, isActiveGroup);
+               addNode(nodes, node, isActiveGroup, system.getContext().isFastCalculation());
                node = (bNode *)node->next;
        }
 
@@ -77,11 +77,11 @@ void ExecutionSystemHelper::addNode(vector<Node *>& nodes, Node *node)
        nodes.push_back(node);
 }
 
-Node *ExecutionSystemHelper::addNode(vector<Node *>& nodes, bNode *b_node, bool inActiveGroup)
+Node *ExecutionSystemHelper::addNode(vector<Node *>& nodes, bNode *b_node, bool inActiveGroup, bool fast)
 {
        Converter converter;
        Node *node;
-       node = converter.convert(b_node);
+       node = converter.convert(b_node, fast);
        node->setIsInActiveGroup(inActiveGroup);
        if (node != NULL) {
                addNode(nodes, node);
index 4b65ed1557778f0e60bc06e56498f9ec30af66db..bd34fe8ab020747316b9b0d0c7addd8965aebe80 100644 (file)
@@ -58,7 +58,7 @@ public:
         * @param bNode node to add
         * @return Node that represents the bNode or null when not able to convert.
         */
-       static Node *addNode(vector<Node *>& nodes, bNode *b_node, bool isInActiveGroup);
+       static Node *addNode(vector<Node *>& nodes, bNode *b_node, bool isInActiveGroup, bool fast);
 
        /**
         * @brief Add a Node to a list
index 7282cf65bc3bca461ae7f118af8b7e281720cb9c..9e48334bccac29a7fa1757a4db9ba0f3412d5722 100644 (file)
@@ -57,8 +57,23 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering)
        /* set progress bar to 0% and status to init compositing*/
        editingtree->progress(editingtree->prh, 0.0);
 
+       bool twopass = (editingtree->flag&NTREE_TWO_PASS) > 0 || rendering;
        /* initialize execution system */
-       ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering);
+       if (twopass) {
+               ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass);
+               system->execute();
+               delete system;
+               
+               if (editingtree->test_break(editingtree->tbh)) {
+                       // during editing multiple calls to this method can be triggered.
+                       // make sure one the last one will be doing the work.
+                       BLI_mutex_unlock(&compositorMutex);
+                       return;
+               }
+       }
+
+       
+       ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false);
        system->execute();
        delete system;
 
index 1a319d67115d853a12ac53f8ec782db492c5a860..b23c1a02b9f97220ae6f2fd4dbbe0439076c4b25 100644 (file)
@@ -64,7 +64,7 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber, Me
        float *buffer = memoryBuffer->getBuffer();
        if (this->m_input->isComplex()) {
                bNode* bnode = this->m_input->getbNode();
-               if (bnode&& bnode->new_node) bnode->new_node->highlight++;
+//             if (bnode&& bnode->new_node) bnode->new_node->highlight++;
 
                void *data = this->m_input->initializeTileData(rect, memoryBuffers);
                int x1 = rect->xmin;
@@ -90,7 +90,7 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber, Me
                        this->m_input->deinitializeTileData(rect, memoryBuffers, data);
                        data = NULL;
                }
-               if (bnode&& bnode->new_node) bnode->new_node->highlight++;
+//             if (bnode&& bnode->new_node) bnode->new_node->highlight++;
        }
        else {
                int x1 = rect->xmin;
@@ -144,7 +144,7 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice* device, rcti *rect,
        clMemToCleanUp->push_back(clOutputBuffer);
        list<cl_kernel> *clKernelsToCleanUp = new list<cl_kernel>();
        bNode* bnode = this->m_input->getbNode();
-       if (bnode&& bnode->new_node) bnode->new_node->highlight++;
+//     if (bnode&& bnode->new_node) bnode->new_node->highlight++;
 
        this->m_input->executeOpenCL(device, outputBuffer, clOutputBuffer, inputMemoryBuffers, clMemToCleanUp, clKernelsToCleanUp);
 
@@ -163,7 +163,7 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice* device, rcti *rect,
        
        this->getMemoryProxy()->getBuffer()->copyContentFrom(outputBuffer);
 
-       if (bnode&& bnode->new_node) bnode->new_node->highlight++;
+//     if (bnode&& bnode->new_node) bnode->new_node->highlight++;
        // STEP 4
 
        
index 79be4d0842d042114a9a09ca62d9e3517d9afe96..21cf142d1cd4b98e362512a7902d461992014d81 100644 (file)
@@ -303,6 +303,7 @@ typedef struct bNodeTree {
 /* ntree->flag */
 #define NTREE_DS_EXPAND                1       /* for animation editors */
 #define NTREE_COM_OPENCL       2       /* use opencl */
+#define NTREE_TWO_PASS         4       /* two pass */
 /* XXX not nice, but needed as a temporary flags
  * for group updates after library linking.
  */
index cb1a45ed9710154eb8994da53ca68d2b0feb0260..1a70745b92a6137b5b4208c69406a1711565ff62 100644 (file)
@@ -4267,6 +4267,10 @@ static void rna_def_composite_nodetree(BlenderRNA *brna)
        prop = RNA_def_property(srna, "use_opencl", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", NTREE_COM_OPENCL);
        RNA_def_property_ui_text(prop, "OpenCL", "Enable GPU calculations");
+
+       prop = RNA_def_property(srna, "two_pass", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", NTREE_TWO_PASS);
+       RNA_def_property_ui_text(prop, "Two Pass", "Use two pass execution during editing; First calculate fast nodes, second pass calculate all nodes.");
 }
 
 static void rna_def_shader_nodetree(BlenderRNA *brna)