[Bf-blender-cvs] [63496f2] compositor-2016: tile manager, start with hilbert spiral

Jeroen Bakker noreply at git.blender.org
Wed Jun 1 20:30:17 CEST 2016


Commit: 63496f2964b0a2da614eb60c33565c241a961eec
Author: Jeroen Bakker
Date:   Wed Jun 1 20:26:49 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rB63496f2964b0a2da614eb60c33565c241a961eec

tile manager, start with hilbert spiral

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

M	source/blender/compositor/CMakeLists.txt
M	source/blender/compositor/cmp/cmp_compositor.cpp
A	source/blender/compositor/cmp/cmp_tilemanager.cpp
A	source/blender/compositor/cmp/cmp_tilemanager.hpp
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_task.cpp
M	source/blender/compositor/device/device_task.hpp
M	source/blender/compositor/kernel/cvm/cvm_node_blur.h
A	source/blender/compositor/kernel/cvm/cvm_node_image.h
M	source/blender/compositor/kernel/cvm/cvm_node_mix.h
D	source/blender/compositor/kernel/cvm/cvm_node_renderlayer.h
M	source/blender/compositor/kernel/cvm/cvm_nodes.h
M	source/blender/compositor/kernel/kernel.h
M	source/blender/compositor/kernel/kernel_functions.h
M	source/blender/compositor/kernel/kernel_types.h

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

diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 7e407b7..0c0d8c2 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -60,6 +60,7 @@ set(SRC
 	cmp/cmp_nodesocket.cpp
 	cmp/cmp_unroll.cpp
 	cmp/cmp_output.cpp
+	cmp/cmp_tilemanager.cpp
 
 	device/device.cpp
 	device/device_task.cpp
@@ -67,6 +68,21 @@ set(SRC
 	device/device_glsl.cpp
 )
 
+# Kernels
+data_to_c_simple(kernel/kernel.h SRC)
+data_to_c_simple(kernel/kernel_types.h SRC)
+data_to_c_simple(kernel/kernel_functions.h SRC)
+data_to_c_simple(kernel/kernel_constants.h SRC)
+
+# CVM Nodes
+data_to_c_simple(kernel/cvm/cvm_node_blur.h SRC)
+data_to_c_simple(kernel/cvm/cvm_node_color.h SRC)
+data_to_c_simple(kernel/cvm/cvm_node_dummy.h SRC)
+data_to_c_simple(kernel/cvm/cvm_node_mix.h SRC)
+data_to_c_simple(kernel/cvm/cvm_node_image.h SRC)
+data_to_c_simple(kernel/cvm/cvm_node_value.h SRC)
+data_to_c_simple(kernel/cvm/cvm_node_viewer.h SRC)
+
 #list(APPEND INC
 #	${CMAKE_CURRENT_BINARY_DIR}/operations
 #)
diff --git a/source/blender/compositor/cmp/cmp_compositor.cpp b/source/blender/compositor/cmp/cmp_compositor.cpp
index 57ae4ea..8b37782 100644
--- a/source/blender/compositor/cmp/cmp_compositor.cpp
+++ b/source/blender/compositor/cmp/cmp_compositor.cpp
@@ -8,7 +8,8 @@ extern "C" {
 #include "cmp_unroll.hpp"
 #include "cmp_output.hpp"
 #include "cmp_rendercontext.hpp"
-#include "device_cpu.hpp"
+#include "cmp_tilemanager.hpp"
+#include "device.hpp"
 #include <iostream>
 
 static ThreadMutex s_compositorMutex;
@@ -35,69 +36,64 @@ void COM_execute(RenderData *rd, Scene *scene, bNodeTree *editingtree, int rende
   Compositor::RenderContext *render_context = new Compositor::RenderContext();
   render_context->view_name = viewName;
 
+  int default_iteration = 1;
+  int default_xy_subsamples = 8;
+
+  if (!rendering) {
+    switch (editingtree->edit_quality) {
+      case NTREE_QUALITY_LOW:
+        default_iteration = 2;
+        default_xy_subsamples = 2;
+        break;
+  
+      case NTREE_QUALITY_MEDIUM:
+        default_iteration = 4;
+        default_xy_subsamples = 4;
+        break;
+
+      case NTREE_QUALITY_HIGH:
+        default_iteration = 8;
+        default_xy_subsamples = 8;
+        break;
+    }
+  }
+
   // UNROLL editingtree
   Compositor::Node* node = Compositor::unroll(editingtree, render_context);
   if (node != NULL) {
     // SELECT DEVICE
-    Compositor::Device::Device *device = new Compositor::Device::DeviceCPU();
-    device->init(node);
+    Compositor::Device::Device *device = Compositor::Device::Device::create_device(node);
 
     // ALLOCATE output
     Compositor::Output output(editingtree, node, rd, viewName, viewSettings, displaySettings);
 
     // Generate Tiles
-    const int width = output.width;
-    const int height = output.height;
-    const int tile_size = editingtree->chunksize;
-    int num_x_tiles = (width + tile_size) / tile_size;
-    int num_y_tiles = (height + tile_size) / tile_size;
-    int num_tiles = num_x_tiles * num_y_tiles;
-    Compositor::Device::Task** tasks = new Compositor::Device::Task*[num_x_tiles*num_y_tiles];
-    for (int i = 0 ; i < num_tiles; i ++) tasks[i] = NULL;
-
-    int tile_index = 0;
-    for (int x = 0 ; x <= width; x += tile_size) {
-      int x_max = x+tile_size;
-      if (x_max > width) x_max = width;
-      for (int y = 0;y <= height; y += tile_size) {
-        int y_max = y+tile_size;
-        if (y_max > height) y_max = height;
-
-        Compositor::Device::Task* task = new Compositor::Device::Task(node, x, y, x_max, y_max, &output);
-        task->max_iteration = 1000;
-        tasks[tile_index++] = task;
-      }
-    }
+    Compositor::TileManager tile_manager(&output);
+    std::list<Compositor::Device::Task*> tiles;
+    tile_manager.generate_tiles(tiles);
+
     // Schedule
     device->start();
-    for (int i = 0 ; i < num_tiles; i ++) {
-      Compositor::Device::Task *task = tasks[i];
-      if (task != NULL) {
-        device->add_task(task);
-      }
+    for (std::list<Compositor::Device::Task*>::iterator it=tiles.begin(); it != tiles.end(); ++it) {
+      Compositor::Device::Task *task = *it;
+      task->max_iteration = default_iteration;
+      task->xy_subsamples = default_xy_subsamples;
+      device->add_task(task);
     }
     device->wait();
     device->stop();
 
 
     // output.update_subimage(0, 0, output.width, output.height);
-
-    delete device;
-    for (int i = 0 ; i < num_tiles; i ++) {
-      Compositor::Device::Task *task = tasks[i];
-      if (task != NULL) {
-        delete(task);
-      }
-    }
+    Compositor::Device::Device::destroy_device(device);
+    tile_manager.delete_tiles(tiles);
   }
 
   delete render_context;
   BLI_mutex_unlock(&s_compositorMutex);
-
-
-
 }
 
+
 void COM_deinitialize(void) {
   if (is_compositorMutex_init) {
     BLI_mutex_lock(&s_compositorMutex);
diff --git a/source/blender/compositor/cmp/cmp_tilemanager.cpp b/source/blender/compositor/cmp/cmp_tilemanager.cpp
new file mode 100644
index 0000000..79d90e2
--- /dev/null
+++ b/source/blender/compositor/cmp/cmp_tilemanager.cpp
@@ -0,0 +1,64 @@
+#include "cmp_tilemanager.hpp"
+
+#define CMP_DEVICE_CPU
+#define __cvm_inline inline
+#include "kernel_functions.h"
+
+namespace Compositor {
+  inline int2 hilbert_index_to_pos(int n, int d)
+  {
+  	int2 r, xy = make_int2(0, 0);
+  	for(int s = 1; s < n; s *= 2) {
+  		r.x = (d >> 1) & 1;
+  		r.y = (d ^ r.x) & 1;
+  		if(!r.y) {
+  			if(r.x) {
+  				xy = make_int2(s-1, s-1) - xy;
+  			}
+  			swap(xy.x, xy.y);
+  		}
+  		xy += r*make_int2(s, s);
+  		d >>= 2;
+  	}
+  	return xy;
+  }
+
+  enum SpiralDirection {
+  	DIRECTION_UP,
+  	DIRECTION_LEFT,
+  	DIRECTION_DOWN,
+  	DIRECTION_RIGHT,
+  };
+
+
+  TileManager::TileManager(Output* output) {
+    this->output = output;
+  }
+
+  void TileManager::generate_tiles(std::list<Compositor::Device::Task*>& tiles) {
+    Node* node = output->node;
+    const int width = output->width;
+    const int height = output->height;
+    const int tile_size = output->node_tree->chunksize;
+
+    for (int x = 0 ; x <= width; x += tile_size) {
+      int x_max = x+tile_size;
+      if (x_max > width) x_max = width;
+      for (int y = 0;y <= height; y += tile_size) {
+        int y_max = y+tile_size;
+        if (y_max > height) y_max = height;
+
+        Compositor::Device::Task* task = new Compositor::Device::Task(node, x, y, x_max, y_max, this->output);
+        tiles.push_back(task);
+      }
+    }
+  }
+  void TileManager::delete_tiles(std::list<Compositor::Device::Task*>& tiles) {
+    while (!tiles.empty())
+    {
+      Compositor::Device::Task *task = tiles.front();
+      tiles.pop_front();
+      delete(task);
+    }
+  }
+}
diff --git a/source/blender/compositor/cmp/cmp_tilemanager.hpp b/source/blender/compositor/cmp/cmp_tilemanager.hpp
new file mode 100644
index 0000000..80de564
--- /dev/null
+++ b/source/blender/compositor/cmp/cmp_tilemanager.hpp
@@ -0,0 +1,22 @@
+#ifndef CMP_TILEMANAGER_HPP
+#define CMP_TILEMANAGER_HPP
+#include <list>
+#include "device_task.hpp"
+#include "cmp_output.hpp"
+
+namespace Compositor {
+  struct TileManager {
+    Output* output;
+
+    TileManager(Output* output);
+
+    /**
+     * Fills an empty list of tiles with tiles that needs to be calculated.
+     * list will be in order..
+     */
+    void generate_tiles(std::list<Compositor::Device::Task*>& result);
+
+    void delete_tiles(std::list<Compositor::Device::Task*>& tiles);
+  };
+}
+#endif
diff --git a/source/blender/compositor/device/device.cpp b/source/blender/compositor/device/device.cpp
index 66a53e3..b54aac2 100644
--- a/source/blender/compositor/device/device.cpp
+++ b/source/blender/compositor/device/device.cpp
@@ -1,4 +1,7 @@
 #include "device.hpp"
+
+#include "device_cpu.hpp"
+
 namespace Compositor {
   namespace Device {
     Device::~Device() {
@@ -41,5 +44,15 @@ namespace Compositor {
     void Device::wait() {
       BLI_thread_queue_wait_finish(this->queue);
     }
+
+    // FACTORY methods
+    Device* Device::create_device(Node* node) {
+      Device* device = new DeviceCPU();
+      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 c8f114d..11d5c68 100644
--- a/source/blender/compositor/device/device.hpp
+++ b/source/blender/compositor/device/device.hpp
@@ -37,6 +37,16 @@ namespace Compositor {
       virtual void start();
       virtual void stop();
       virtual void wait();
+
+      /**
+       * Create a device that is capable to calculate the given node(tree).
+       * DeviceGLSL is (more) limited in Memory and number of textures.
+       * this function counts the number of needed texture slots and try to reserve the
+       * space for it. When it worked this DeviceGLSL will be returned.
+       * otherwise a DeviceCPU instance will be returned.
+       */
+      static Device* create_device(Node* node);
+      static void destroy_device(Device* device);
     };
   }
 }
diff --git a/source/blender/compositor/device/device_cpu.cpp b/source/blender/compositor/device/device_cpu.cpp
index 5a5c6ea..b7ff6e4 100644
--- a/source/blender/compositor/device/device_cpu.cpp
+++ b/source/blender/compositor/device/device_cpu.cpp
@@ -94,8 +94,8 @@ namespace Compositor {
       if (task->is_cancelled()) { return; }
       // perform task
       KernelGlobal globals;
-      globals.phase = KG_PHASE_REFINE;
-      globals.subpixel_samples_xy = 4;
+      globals.phase = task->iteration < task->max_iteration?KG_PHASE_REFINE: KG_PHASE_FINAL;
+      globals.subpixel_samples_xy = task->xy_subsamples;
       globals.width = 960;
 
       Node* node = task->node;
@@ -109,18 +109,26 @@ namespace Compositor {
         for (int x = task->x_min; x < task->x_max ; x ++) {
           float2 xy = make_float2((float)x, (float)y);
           float4 color = node_execute_float4(globals, node->stack_index, xy, NULL);
-          buffer[offset] = ((buffer[offset]*prev_iteration)+color.x)/curr_iteration;
-          buffer[offset+1] =

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list