[Bf-blender-cvs] [10645a93727] temp-compositor-single-threaded-operation: Compositor: Merge SingleThreadedOperation with WriteBufferOperation.

Jeroen Bakker noreply at git.blender.org
Tue Mar 30 16:09:14 CEST 2021


Commit: 10645a93727dc7f5c174800333f9a728bd6fc1a8
Author: Jeroen Bakker
Date:   Tue Mar 30 16:07:03 2021 +0200
Branches: temp-compositor-single-threaded-operation
https://developer.blender.org/rB10645a93727dc7f5c174800333f9a728bd6fc1a8

Compositor: Merge SingleThreadedOperation with WriteBufferOperation.

Single threaded operations always creates a buffer around and write
buffer operation would sample that buffer one pixel at a time. This
refactor would push the samples in one go to the output buffer by
merging the write buffer and single threaded operation.

Less code complexity, less needed CPU cycles and less memory would be
needed.

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

M	source/blender/compositor/intern/COM_ExecutionGroup.cc
M	source/blender/compositor/intern/COM_NodeOperationBuilder.cc
M	source/blender/compositor/intern/COM_SingleThreadedOperation.cc
M	source/blender/compositor/intern/COM_SingleThreadedOperation.h
M	source/blender/compositor/operations/COM_DenoiseOperation.cc
M	source/blender/compositor/operations/COM_DenoiseOperation.h
M	source/blender/compositor/operations/COM_GlareBaseOperation.cc
M	source/blender/compositor/operations/COM_GlareBaseOperation.h
M	source/blender/compositor/operations/COM_WriteBufferOperation.cc
M	source/blender/compositor/operations/COM_WriteBufferOperation.h

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

diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cc b/source/blender/compositor/intern/COM_ExecutionGroup.cc
index 87c9e6e8a69..f0e205eb44a 100644
--- a/source/blender/compositor/intern/COM_ExecutionGroup.cc
+++ b/source/blender/compositor/intern/COM_ExecutionGroup.cc
@@ -102,11 +102,11 @@ bool ExecutionGroup::addOperation(NodeOperation *operation)
     return false;
   }
 
-  if (!operation->get_flags().is_read_buffer_operation &&
-      !operation->get_flags().is_write_buffer_operation) {
+  if ((!operation->get_flags().is_read_buffer_operation &&
+       !operation->get_flags().is_write_buffer_operation) ||
+      operation->get_flags().single_threaded) {
     m_flags.complex = operation->get_flags().complex;
     m_flags.open_cl = operation->get_flags().open_cl;
-    m_flags.single_threaded = operation->get_flags().single_threaded;
     m_flags.initialized = true;
   }
 
diff --git a/source/blender/compositor/intern/COM_NodeOperationBuilder.cc b/source/blender/compositor/intern/COM_NodeOperationBuilder.cc
index fdd48da3fb4..e0d24e88e10 100644
--- a/source/blender/compositor/intern/COM_NodeOperationBuilder.cc
+++ b/source/blender/compositor/intern/COM_NodeOperationBuilder.cc
@@ -490,6 +490,11 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation,
   }
 
   WriteBufferOperation *writeOperation = nullptr;
+  if (operation->get_flags().is_write_buffer_operation) {
+    writeOperation = static_cast<WriteBufferOperation *>(operation);
+    writeOperation->setbNodeTree(m_context->getbNodeTree());
+  }
+
   for (NodeOperationInput *target : targets) {
     /* try to find existing write buffer operation */
     if (target->getOperation().get_flags().is_write_buffer_operation) {
diff --git a/source/blender/compositor/intern/COM_SingleThreadedOperation.cc b/source/blender/compositor/intern/COM_SingleThreadedOperation.cc
index 01be6e1afed..09601bdc3c5 100644
--- a/source/blender/compositor/intern/COM_SingleThreadedOperation.cc
+++ b/source/blender/compositor/intern/COM_SingleThreadedOperation.cc
@@ -20,44 +20,42 @@
 
 namespace blender::compositor {
 
-SingleThreadedOperation::SingleThreadedOperation()
+SingleThreadedOperation::SingleThreadedOperation(DataType data_type)
+    : WriteBufferOperation(data_type, false)
 {
-  this->m_cachedInstance = nullptr;
+  addOutputSocket(data_type);
   flags.complex = true;
   flags.single_threaded = true;
 }
 
 void SingleThreadedOperation::initExecution()
 {
+  WriteBufferOperation::initExecution();
   initMutex();
 }
 
-void SingleThreadedOperation::executePixel(float output[4], int x, int y, void * /*data*/)
-{
-  this->m_cachedInstance->readNoCheck(output, x, y);
-}
-
 void SingleThreadedOperation::deinitExecution()
 {
+  WriteBufferOperation::deinitExecution();
   deinitMutex();
-  if (this->m_cachedInstance) {
-    delete this->m_cachedInstance;
-    this->m_cachedInstance = nullptr;
-  }
 }
-void *SingleThreadedOperation::initializeTileData(rcti *rect)
+
+void SingleThreadedOperation::executeRegion(rcti *rect, unsigned int UNUSED(tile_number))
 {
-  if (this->m_cachedInstance) {
-    return this->m_cachedInstance;
+  if (executed) {
+    return;
   }
-
   lockMutex();
-  if (this->m_cachedInstance == nullptr) {
-    //
-    this->m_cachedInstance = createMemoryBuffer(rect);
+  if (executed) {
+    return;
   }
+
+  MemoryBuffer buffer = createMemoryBuffer(rect);
+  MemoryBuffer *memory_buffer = getMemoryProxy()->getBuffer();
+  memory_buffer->fill_from(buffer);
+
   unlockMutex();
-  return this->m_cachedInstance;
+  executed = true;
 }
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_SingleThreadedOperation.h b/source/blender/compositor/intern/COM_SingleThreadedOperation.h
index 9945f938ff9..db460a561d6 100644
--- a/source/blender/compositor/intern/COM_SingleThreadedOperation.h
+++ b/source/blender/compositor/intern/COM_SingleThreadedOperation.h
@@ -18,27 +18,22 @@
 
 #pragma once
 
-#include "COM_NodeOperation.h"
+#include "COM_WriteBufferOperation.h"
 
 namespace blender::compositor {
 
-class SingleThreadedOperation : public NodeOperation {
+class SingleThreadedOperation : public WriteBufferOperation {
  private:
-  MemoryBuffer *m_cachedInstance;
+  bool executed = false;
 
  protected:
-  inline bool isCached()
+  bool is_executed()
   {
-    return this->m_cachedInstance != nullptr;
+    return executed;
   }
 
  public:
-  SingleThreadedOperation();
-
-  /**
-   * The inner loop of this operation.
-   */
-  void executePixel(float output[4], int x, int y, void *data) override;
+  SingleThreadedOperation(DataType data_type);
 
   /**
    * Initialize the execution
@@ -50,9 +45,9 @@ class SingleThreadedOperation : public NodeOperation {
    */
   void deinitExecution() override;
 
-  void *initializeTileData(rcti *rect) override;
+  void executeRegion(rcti *rect, unsigned int tile_number) override;
 
-  virtual MemoryBuffer *createMemoryBuffer(rcti *rect) = 0;
+  virtual MemoryBuffer createMemoryBuffer(rcti *rect) = 0;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_DenoiseOperation.cc b/source/blender/compositor/operations/COM_DenoiseOperation.cc
index 587afdc2d00..eebf03fc550 100644
--- a/source/blender/compositor/operations/COM_DenoiseOperation.cc
+++ b/source/blender/compositor/operations/COM_DenoiseOperation.cc
@@ -28,12 +28,11 @@ static pthread_mutex_t oidn_lock = BLI_MUTEX_INITIALIZER;
 
 namespace blender::compositor {
 
-DenoiseOperation::DenoiseOperation()
+DenoiseOperation::DenoiseOperation() : SingleThreadedOperation(DataType::Color)
 {
   this->addInputSocket(DataType::Color);
   this->addInputSocket(DataType::Vector);
   this->addInputSocket(DataType::Color);
-  this->addOutputSocket(DataType::Color);
   this->m_settings = nullptr;
 }
 void DenoiseOperation::initExecution()
@@ -52,7 +51,7 @@ void DenoiseOperation::deinitExecution()
   SingleThreadedOperation::deinitExecution();
 }
 
-MemoryBuffer *DenoiseOperation::createMemoryBuffer(rcti *rect2)
+MemoryBuffer DenoiseOperation::createMemoryBuffer(rcti *rect2)
 {
   MemoryBuffer *tileColor = (MemoryBuffer *)this->m_inputProgramColor->initializeTileData(rect2);
   MemoryBuffer *tileNormal = (MemoryBuffer *)this->m_inputProgramNormal->initializeTileData(rect2);
@@ -62,8 +61,8 @@ MemoryBuffer *DenoiseOperation::createMemoryBuffer(rcti *rect2)
   rect.ymin = 0;
   rect.xmax = getWidth();
   rect.ymax = getHeight();
-  MemoryBuffer *result = new MemoryBuffer(DataType::Color, rect);
-  float *data = result->getBuffer();
+  MemoryBuffer result(DataType::Color, rect);
+  float *data = result.getBuffer();
   this->generateDenoise(data, tileColor, tileNormal, tileAlbedo, this->m_settings);
   return result;
 }
@@ -72,7 +71,7 @@ bool DenoiseOperation::determineDependingAreaOfInterest(rcti * /*input*/,
                                                         ReadBufferOperation *readOperation,
                                                         rcti *output)
 {
-  if (isCached()) {
+  if (is_executed()) {
     return false;
   }
 
diff --git a/source/blender/compositor/operations/COM_DenoiseOperation.h b/source/blender/compositor/operations/COM_DenoiseOperation.h
index a9298c17e92..7d468b3a53f 100644
--- a/source/blender/compositor/operations/COM_DenoiseOperation.h
+++ b/source/blender/compositor/operations/COM_DenoiseOperation.h
@@ -64,7 +64,7 @@ class DenoiseOperation : public SingleThreadedOperation {
                        MemoryBuffer *inputTileAlbedo,
                        NodeDenoise *settings);
 
-  MemoryBuffer *createMemoryBuffer(rcti *rect) override;
+  MemoryBuffer createMemoryBuffer(rcti *rect) override;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.cc b/source/blender/compositor/operations/COM_GlareBaseOperation.cc
index 90755d9f27a..a0ef4724107 100644
--- a/source/blender/compositor/operations/COM_GlareBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_GlareBaseOperation.cc
@@ -21,10 +21,9 @@
 
 namespace blender::compositor {
 
-GlareBaseOperation::GlareBaseOperation()
+GlareBaseOperation::GlareBaseOperation() : SingleThreadedOperation(DataType::Color)
 {
   this->addInputSocket(DataType::Color);
-  this->addOutputSocket(DataType::Color);
   this->m_settings = nullptr;
 }
 void GlareBaseOperation::initExecution()
@@ -39,7 +38,7 @@ void GlareBaseOperation::deinitExecution()
   SingleThreadedOperation::deinitExecution();
 }
 
-MemoryBuffer *GlareBaseOperation::createMemoryBuffer(rcti *rect2)
+MemoryBuffer GlareBaseOperation::createMemoryBuffer(rcti *rect2)
 {
   MemoryBuffer *tile = (MemoryBuffer *)this->m_inputProgram->initializeTileData(rect2);
   rcti rect;
@@ -47,8 +46,8 @@ MemoryBuffer *GlareBaseOperation::createMemoryBuffer(rcti *rect2)
   rect.ymin = 0;
   rect.xmax = getWidth();
   rect.ymax = getHeight();
-  MemoryBuffer *result = new MemoryBuffer(DataType::Color, rect);
-  float *data = result->getBuffer();
+  MemoryBuffer result(DataType::Color, rect);
+  float *data = result.getBuffer();
   this->generateGlare(data, tile, this->m_settings);
   return result;
 }
@@ -57,7 +56,7 @@ bool GlareBaseOperation::determineDependingAreaOfInterest(rcti * /*input*/,
                                                           ReadBufferOperation *readOperation,
                                                           rcti *output)
 {
-  if (isCached()) {
+  if (is_executed()) {
     return false;
   }
 
diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.h b/source/blender/compositor/operations/COM_GlareBaseOperation.h
index 7ae15595e3b..cb485d8a90b 100644
--- a/source/blender/compositor/operations/COM_GlareBaseOperation.h
+++ b/source/blender/compositor/operations/COM_GlareBaseOperation.h
@@ -73,7 +73,7 @@ class GlareBaseOperation : public SingleThreadedOperation {
 
   virtual void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings) = 0;
 
-  MemoryBuffer *createMemoryBuffer(rcti *rect) override;
+  MemoryBuffer createMemoryBuffer(rcti *rect) override;
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cc b/source/ble

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list