[Bf-blender-cvs] [6df1386] compositor-2016: Initial GLSL code generation

Jeroen Bakker noreply at git.blender.org
Thu Jun 2 17:40:46 CEST 2016


Commit: 6df13860bdf0fe71b3bff40eac52849eb4bcb142
Author: Jeroen Bakker
Date:   Thu Jun 2 17:40:28 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rB6df13860bdf0fe71b3bff40eac52849eb4bcb142

Initial GLSL code generation

===================================================================

M	source/blender/compositor/CMakeLists.txt
M	source/blender/compositor/cmp/cmp_node.cpp
M	source/blender/compositor/cmp/cmp_node.hpp
M	source/blender/compositor/cmp/cmp_nodesocket.cpp
M	source/blender/compositor/device/device.cpp
M	source/blender/compositor/device/device.hpp
M	source/blender/compositor/device/device_cpu.cpp
M	source/blender/compositor/device/device_glsl.cpp
M	source/blender/compositor/device/device_glsl.hpp
A	source/blender/compositor/device/device_glsl_compiler.cpp
A	source/blender/compositor/device/device_glsl_compiler.hpp

===================================================================

diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 0c0d8c2..9a6d4da 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -66,6 +66,7 @@ set(SRC
 	device/device_task.cpp
 	device/device_cpu.cpp
 	device/device_glsl.cpp
+	device/device_glsl_compiler.cpp
 )
 
 # Kernels
diff --git a/source/blender/compositor/cmp/cmp_node.cpp b/source/blender/compositor/cmp/cmp_node.cpp
index aaf4747..69f4b45 100644
--- a/source/blender/compositor/cmp/cmp_node.cpp
+++ b/source/blender/compositor/cmp/cmp_node.cpp
@@ -9,16 +9,35 @@ extern "C" {
 #  include "RE_pipeline.h"
 #  include "RE_shader_ext.h"
 #  include "RE_render_ext.h"
+
+  extern char datatoc_cvm_node_viewer_h[];
+  extern char datatoc_cvm_node_value_h[];
+  extern char datatoc_cvm_node_color_h[];
+  extern char datatoc_cvm_node_dummy_h[];
+  extern char datatoc_cvm_node_blur_h[];
+  extern char datatoc_cvm_node_image_h[];
 }
 
 
 namespace Compositor {
-  Node::Node() {
+  Node::Node(int type) {
+    this->type = type;
     this->node_tree = NULL;
     this->b_node = NULL;
     this->stack_index = -1;
     this->texture_index = -1;
     this->buffer = NULL;
+    this->glsl_template = "// UNKNOWN\n";
+
+    switch (type) {
+      case CMP_NODE_VALUE:
+        this->glsl_template = std::string(datatoc_cvm_node_value_h);
+        break;
+
+      case CMP_NODE_MIX_RGB:
+        this->glsl_template = std::string(datatoc_cvm_node_color_h);
+        break;
+      }
   }
 
   Node::Node(bNodeTree* node_tree, bNode *node, RenderContext * render_context) {
@@ -27,6 +46,7 @@ namespace Compositor {
     this->stack_index = -1;
     this->texture_index = -1;
     this->buffer = NULL;
+    this->glsl_template = std::string(datatoc_cvm_node_dummy_h);
 
     this->type = node->type;
 
@@ -35,12 +55,18 @@ namespace Compositor {
     }
 
     switch (node->type) {
+      case CMP_NODE_VIEWER:
+        this->glsl_template = std::string(datatoc_cvm_node_viewer_h);
+        break;
+
       case CMP_NODE_MIX_RGB:
+      this->glsl_template = std::string(datatoc_cvm_node_color_h);
         this->var_int_0 = node->custom1;
         break;
 
       case CMP_NODE_BLUR:
         {
+          this->glsl_template = std::string(datatoc_cvm_node_blur_h);
           NodeBlurData *data = (NodeBlurData *)node->storage;
           // TODO: other elemetns in the data including needed conversions.
           this->var_float_0 = data->percentx/100.f;
@@ -49,12 +75,14 @@ namespace Compositor {
         break;
 
       case CMP_NODE_VALUE:
+        this->glsl_template = std::string(datatoc_cvm_node_value_h);
         PointerRNA ptr;
         RNA_pointer_create((ID *)node_tree, &RNA_NodeSocket, node->outputs.first, &ptr);
         this->var_float_0 = RNA_float_get(&ptr, "default_value");
         break;
 
       case CMP_NODE_R_LAYERS:
+      this->glsl_template = std::string(datatoc_cvm_node_image_h);
         short layer_id = node->custom1;
         Scene* scene = (Scene*)node->id;
 
diff --git a/source/blender/compositor/cmp/cmp_node.hpp b/source/blender/compositor/cmp/cmp_node.hpp
index 42e2dd4..3627823 100644
--- a/source/blender/compositor/cmp/cmp_node.hpp
+++ b/source/blender/compositor/cmp/cmp_node.hpp
@@ -8,6 +8,7 @@ namespace Compositor {
 #include "cmp_nodesocket.hpp"
 #include "cmp_rendercontext.hpp"
 #include <list>
+#include <string>
 
 namespace Compositor {
   struct Node {
@@ -39,11 +40,13 @@ namespace Compositor {
     int buffer_width;
     int buffer_height;
 
+    std::string glsl_template;
+
     std::list<NodeSocket*> inputs;
 
     // TODO: Needs optional parameter with output socket you are evaluating.
     Node(bNodeTree* node_tree, bNode *node, RenderContext * render_context);
-    Node();
+    Node(int type);
     ~Node();
   };
 }
diff --git a/source/blender/compositor/cmp/cmp_nodesocket.cpp b/source/blender/compositor/cmp/cmp_nodesocket.cpp
index 92dd655..379478b 100644
--- a/source/blender/compositor/cmp/cmp_nodesocket.cpp
+++ b/source/blender/compositor/cmp/cmp_nodesocket.cpp
@@ -28,8 +28,7 @@ namespace Compositor {
         RNA_pointer_create((ID *)node_tree, &RNA_NodeSocket, socket, &ptr);
         default_value = RNA_float_get(&ptr, "default_value");
 
-        connected_node = new Node();
-        connected_node->type = CMP_NODE_VALUE;
+        connected_node = new Node(CMP_NODE_VALUE);
         connected_node->var_float_0 = default_value;
         this->connected_node = connected_node;
         break;
@@ -38,8 +37,7 @@ namespace Compositor {
         RNA_pointer_create((ID *)node_tree, &RNA_NodeSocket, socket, &ptr);
         RNA_float_get_array(&ptr, "default_value", default_color);
 
-        connected_node = new Node();
-        connected_node->type = CMP_NODE_RGB;
+        connected_node = new Node(CMP_NODE_RGB);
         connected_node->var_float_0 = default_color[0];
         connected_node->var_float_1 = default_color[1];
         connected_node->var_float_2 = default_color[2];
diff --git a/source/blender/compositor/device/device.cpp b/source/blender/compositor/device/device.cpp
index b54aac2..8640049 100644
--- a/source/blender/compositor/device/device.cpp
+++ b/source/blender/compositor/device/device.cpp
@@ -1,12 +1,23 @@
 #include "device.hpp"
 
 #include "device_cpu.hpp"
+#include "device_glsl.hpp"
+#include <iostream>
 
 namespace Compositor {
   namespace Device {
     Device::~Device() {
 
     }
+
+    void Device::set_num_workers(int num_workers) {
+      this->num_workers = num_workers;
+    }
+
+    int Device::get_num_workers() {
+      return this->num_workers;
+    }
+
     void *Device::thread_execute(void *data) {
       Device *device = (Device*) data;
       Task * task;
@@ -22,7 +33,6 @@ namespace Compositor {
     }
 
     void Device::init(Compositor::Node* node) {
-
     }
 
     void Device::add_task(Task* task) {
@@ -31,8 +41,9 @@ namespace Compositor {
 
     void Device::start() {
       this->queue  = BLI_thread_queue_init();
-      BLI_init_threads(&this->threads, thread_execute, 4);
-      for (int i = 0 ; i < 4 ; i ++ ) {
+
+      BLI_init_threads(&this->threads, thread_execute, num_workers);
+      for (int i = 0 ; i < num_workers ; i ++ ) {
         BLI_insert_thread(&this->threads, this);
       }
     }
@@ -46,11 +57,19 @@ namespace Compositor {
     }
 
     // FACTORY methods
+//#define SELECT_DEVICE_GLSL
+
     Device* Device::create_device(Node* node) {
+#ifdef SELECT_DEVICE_GLSL
+      Device* device = new DeviceGLSL();
+#else
       Device* device = new DeviceCPU();
+#endif
+
       device->init(node);
       return device;
     }
+
     void Device::destroy_device(Device* device) {
       delete device;
     }
diff --git a/source/blender/compositor/device/device.hpp b/source/blender/compositor/device/device.hpp
index 11d5c68..f45995e 100644
--- a/source/blender/compositor/device/device.hpp
+++ b/source/blender/compositor/device/device.hpp
@@ -24,6 +24,11 @@ namespace Compositor {
       ThreadQueue *queue;
       ListBase threads;
       static void *thread_execute(void *data);
+      int num_workers;
+
+    protected:
+      void set_num_workers(int num_workers);
+      int get_num_workers();
 
     public:
       virtual ~Device();
diff --git a/source/blender/compositor/device/device_cpu.cpp b/source/blender/compositor/device/device_cpu.cpp
index b7ff6e4..b22ffb2 100644
--- a/source/blender/compositor/device/device_cpu.cpp
+++ b/source/blender/compositor/device/device_cpu.cpp
@@ -83,6 +83,7 @@ namespace Compositor {
     }
 
     void DeviceCPU::init(Node* node) {
+      set_num_workers(BLI_system_thread_count());
       int next_stack_index = 0;
       int next_texture_index = 0;
       set_stack_index(node, &next_stack_index, &next_texture_index);
diff --git a/source/blender/compositor/device/device_glsl.cpp b/source/blender/compositor/device/device_glsl.cpp
index 0e7d936..ee52b15 100644
--- a/source/blender/compositor/device/device_glsl.cpp
+++ b/source/blender/compositor/device/device_glsl.cpp
@@ -1,7 +1,20 @@
-#include "device_cpu.hpp"
+#include "device_glsl.hpp"
+#include <iostream>
+#include "device_glsl_compiler.hpp"
 
 namespace Compositor {
   namespace Device {
-    
+    void DeviceGLSL::init(Compositor::Node* node) {
+      set_num_workers(1);
+
+      std::string glsl_source = generate_glsl_source(node);
+      std::cout << glsl_source << "\n";
+    }
+
+    void DeviceGLSL::execute_task(Task* task) {
+    }
+
+    void DeviceGLSL::task_finished(Task* task) {
+    }
   }
 }
diff --git a/source/blender/compositor/device/device_glsl.hpp b/source/blender/compositor/device/device_glsl.hpp
index acbc1c1..201c08e 100644
--- a/source/blender/compositor/device/device_glsl.hpp
+++ b/source/blender/compositor/device/device_glsl.hpp
@@ -5,8 +5,13 @@
 
 namespace Compositor {
   namespace Device {
-    class DeviceGLSL {
+    class DeviceGLSL: public Device {
 
+    public:
+      void init(Compositor::Node* node);
+
+      void execute_task(Task* task);
+      void task_finished(Task* task);
     };
   }
 }
diff --git a/source/blender/compositor/device/device_glsl_compiler.cpp b/source/blender/compositor/device/device_glsl_compiler.cpp
new file mode 100644
index 0000000..b49c789
--- /dev/null
+++ b/source/blender/compositor/device/device_glsl_compiler.cpp
@@ -0,0 +1,24 @@
+#include "device_glsl_compiler.hpp"
+
+namespace Compositor {
+  namespace Device {
+    void build_source(std::stringstream& out, Compositor::Node* node) {
+      for (std::list<NodeSocket*>::const_iterator iterator = node->inputs.begin(), end = node->inputs.end(); iterator != end; ++iterator) {
+        NodeSocket* socket = *iterator;
+        build_source(out, socket->connected_node);
+      }
+
+      out << "// START Node\n";
+      out << node->glsl_template;
+      out << "// END Node\n";
+    }
+
+    std::string generate_glsl_source(Compositor::Node* node) {
+      std::stringstream source;
+      source << "// START GLSL Compositor source\n";
+      build_source(source, node);
+      source << "// END GLSL Compositor source\n";
+      return source.str();
+    }
+  }
+}
diff --git a/source/blender/compositor/device/device_glsl_compiler.hpp b/source/blender/compositor/device/d

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list