[Bf-blender-cvs] [9adfd278f74] master: Compositor: Full-frame base system
Manuel Castilla
noreply at git.blender.org
Tue Jun 1 10:56:46 CEST 2021
Commit: 9adfd278f7487798f1b0124c7e44cf9934b4ba54
Author: Manuel Castilla
Date: Tue Jun 1 10:25:38 2021 +0200
Branches: master
https://developer.blender.org/rB9adfd278f7487798f1b0124c7e44cf9934b4ba54
Compositor: Full-frame base system
This patch adds the base code needed to make the full-frame system work for both current tiled/per-pixel implementation of operations and full-frame.
Two execution models:
- Tiled: Current implementation. Renders execution groups in tiles from outputs to input. Not all operations are buffered. Runs the tiled/per-pixel implementation.
- FullFrame: All operations are buffered. Fully renders operations from inputs to outputs. Runs full-frame implementation of operations if available otherwise the current tiled/per-pixel. Creates output buffers on first read and free them as soon as all its readers have finished, reducing peak memory usage of complex/long trees. Operations are multi-threaded but do not run in parallel as Tiled (will be done in another patch).
This should allow us to convert operations to full-frame in small steps with the system already working and solve the problem of high memory usage.
FullFrame breaking changes respect Tiled system, mainly:
- Translate, Rotate, Scale, and Transform take effect immediately instead of next buffered operation.
- Any sampling is always done over inputs instead of last buffered operation.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D11113
===================================================================
M release/scripts/startup/bl_ui/space_node.py
M release/scripts/startup/bl_ui/space_userpref.py
M source/blender/compositor/CMakeLists.txt
M source/blender/compositor/COM_defines.h
A source/blender/compositor/intern/COM_BufferOperation.cc
A source/blender/compositor/intern/COM_BufferOperation.h
M source/blender/compositor/intern/COM_CPUDevice.cc
M source/blender/compositor/intern/COM_CompositorContext.cc
M source/blender/compositor/intern/COM_CompositorContext.h
M source/blender/compositor/intern/COM_Debug.cc
M source/blender/compositor/intern/COM_Debug.h
M source/blender/compositor/intern/COM_Enums.h
M source/blender/compositor/intern/COM_ExecutionGroup.cc
A source/blender/compositor/intern/COM_ExecutionModel.cc
A source/blender/compositor/intern/COM_ExecutionModel.h
M source/blender/compositor/intern/COM_ExecutionSystem.cc
M source/blender/compositor/intern/COM_ExecutionSystem.h
A source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
A source/blender/compositor/intern/COM_FullFrameExecutionModel.h
A source/blender/compositor/intern/COM_MultiThreadedOperation.cc
A source/blender/compositor/intern/COM_MultiThreadedOperation.h
M source/blender/compositor/intern/COM_NodeOperation.cc
M source/blender/compositor/intern/COM_NodeOperation.h
M source/blender/compositor/intern/COM_NodeOperationBuilder.cc
A source/blender/compositor/intern/COM_SharedOperationBuffers.cc
A source/blender/compositor/intern/COM_SharedOperationBuffers.h
A source/blender/compositor/intern/COM_TiledExecutionModel.cc
A source/blender/compositor/intern/COM_TiledExecutionModel.h
M source/blender/compositor/intern/COM_WorkPackage.h
M source/blender/compositor/intern/COM_WorkScheduler.cc
M source/blender/compositor/intern/COM_WorkScheduler.h
M source/blender/compositor/nodes/COM_TranslateNode.cc
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesdna/DNA_userdef_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index 89ce742b81e..1208ca0a64a 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -660,8 +660,12 @@ class NODE_PT_quality(bpy.types.Panel):
snode = context.space_data
tree = snode.node_tree
+ prefs = bpy.context.preferences
col = layout.column()
+ if prefs.experimental.use_full_frame_compositor:
+ col.prop(tree, "execution_mode")
+
col.prop(tree, "render_quality", text="Render")
col.prop(tree, "edit_quality", text="Edit")
col.prop(tree, "chunk_size")
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index de78b88c0f6..d85fe16d654 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -2256,6 +2256,7 @@ class USERPREF_PT_experimental_prototypes(ExperimentalPanel, Panel):
context, (
({"property": "use_new_hair_type"}, "T68981"),
({"property": "use_new_point_cloud_type"}, "T75717"),
+ ({"property": "use_full_frame_compositor"}, "T88150"),
),
)
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 65391794c12..ac59d832013 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -49,6 +49,8 @@ set(SRC
COM_compositor.h
COM_defines.h
+ intern/COM_BufferOperation.cc
+ intern/COM_BufferOperation.h
intern/COM_CPUDevice.cc
intern/COM_CPUDevice.h
intern/COM_ChunkOrder.cc
@@ -66,14 +68,20 @@ set(SRC
intern/COM_Enums.cc
intern/COM_ExecutionGroup.cc
intern/COM_ExecutionGroup.h
+ intern/COM_ExecutionModel.cc
+ intern/COM_ExecutionModel.h
intern/COM_ExecutionSystem.cc
intern/COM_ExecutionSystem.h
+ intern/COM_FullFrameExecutionModel.cc
+ intern/COM_FullFrameExecutionModel.h
intern/COM_MemoryBuffer.cc
intern/COM_MemoryBuffer.h
intern/COM_MemoryProxy.cc
intern/COM_MemoryProxy.h
intern/COM_MetaData.cc
intern/COM_MetaData.h
+ intern/COM_MultiThreadedOperation.cc
+ intern/COM_MultiThreadedOperation.h
intern/COM_Node.cc
intern/COM_Node.h
intern/COM_NodeConverter.cc
@@ -86,8 +94,12 @@ set(SRC
intern/COM_NodeOperationBuilder.h
intern/COM_OpenCLDevice.cc
intern/COM_OpenCLDevice.h
+ intern/COM_SharedOperationBuffers.cc
+ intern/COM_SharedOperationBuffers.h
intern/COM_SingleThreadedOperation.cc
intern/COM_SingleThreadedOperation.h
+ intern/COM_TiledExecutionModel.cc
+ intern/COM_TiledExecutionModel.h
intern/COM_WorkPackage.cc
intern/COM_WorkPackage.h
intern/COM_WorkScheduler.cc
diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h
index ef889807030..5a52d216117 100644
--- a/source/blender/compositor/COM_defines.h
+++ b/source/blender/compositor/COM_defines.h
@@ -20,6 +20,16 @@
namespace blender::compositor {
+enum class eExecutionModel {
+ /**
+ * Operations are executed from outputs to inputs grouped in execution groups and rendered
+ * in tiles.
+ */
+ Tiled,
+ /** Operations are fully rendered in order from inputs to outputs. */
+ FullFrame
+};
+
/**
* \brief possible data types for sockets
* \ingroup Model
diff --git a/source/blender/compositor/intern/COM_BufferOperation.cc b/source/blender/compositor/intern/COM_BufferOperation.cc
new file mode 100644
index 00000000000..c1e64142443
--- /dev/null
+++ b/source/blender/compositor/intern/COM_BufferOperation.cc
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+#include "COM_BufferOperation.h"
+
+namespace blender::compositor {
+
+BufferOperation::BufferOperation(MemoryBuffer *buffer, DataType data_type) : NodeOperation()
+{
+ buffer_ = buffer;
+ /* TODO: Implement a MemoryBuffer get_size() method returning a Size2d type. Shorten following
+ * code to: set_resolution(buffer.get_size()) */
+ unsigned int resolution[2];
+ resolution[0] = buffer->getWidth();
+ resolution[1] = buffer->getHeight();
+ setResolution(resolution);
+ addOutputSocket(data_type);
+}
+
+void *BufferOperation::initializeTileData(rcti * /*rect*/)
+{
+ return buffer_;
+}
+
+void BufferOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
+{
+ switch (sampler) {
+ case PixelSampler::Nearest:
+ buffer_->read(output, x, y);
+ break;
+ case PixelSampler::Bilinear:
+ default:
+ buffer_->readBilinear(output, x, y);
+ break;
+ case PixelSampler::Bicubic:
+ /* No bicubic. Same implementation as ReadBufferOperation. */
+ buffer_->readBilinear(output, x, y);
+ break;
+ }
+}
+
+void BufferOperation::executePixelFiltered(
+ float output[4], float x, float y, float dx[2], float dy[2])
+{
+ const float uv[2] = {x, y};
+ const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}};
+ buffer_->readEWA(output, uv, deriv);
+}
+
+} // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_CompositorContext.cc b/source/blender/compositor/intern/COM_BufferOperation.h
similarity index 60%
copy from source/blender/compositor/intern/COM_CompositorContext.cc
copy to source/blender/compositor/intern/COM_BufferOperation.h
index f70f3a8ebfc..f87cd4db94e 100644
--- a/source/blender/compositor/intern/COM_CompositorContext.cc
+++ b/source/blender/compositor/intern/COM_BufferOperation.h
@@ -13,32 +13,25 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * Copyright 2011, Blender Foundation.
+ * Copyright 2021, Blender Foundation.
*/
-#include "COM_CompositorContext.h"
-#include "COM_defines.h"
-#include <cstdio>
+#pragma once
-#include "BLI_assert.h"
+#include "COM_NodeOperation.h"
namespace blender::compositor {
-CompositorContext::CompositorContext()
-{
- this->m_scene = nullptr;
- this->m_rd = nullptr;
- this->m_quality = eCompositorQuality::High;
- this->m_hasActiveOpenCLDevices = false;
- this->m_fastCalculation = false;
- this->m_viewSettings = nullptr;
- this->m_displaySettings = nullptr;
-}
+class BufferOperation : public NodeOperation {
+ private:
+ MemoryBuffer *buffer_;
-int CompositorContext::getFramenumber() const
-{
- BLI_assert(m_rd);
- return m_rd->cfra;
-}
+ public:
+ BufferOperation(MemoryBuffer *buffer, DataType data_type);
+
+ void *initializeTileData(rcti *rect) override;
+ void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
+ void executePixelFiltered(float output[4], float x, float y, float dx[2], float dy[2]) override;
+};
} // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_CPUDevice.cc b/source/blender/compositor/intern/COM_CPUDevice.cc
index 29a82bec636..2ca5557e278 100644
--- a/source/blender/compositor/intern/COM_CPUDevice.cc
+++ b/source/blender/compositor/intern/COM_CPUDevice.cc
@@ -30,11 +30,24 @@ CPUDevice::CPUDevice(int thread_id) : m_thread_id(thread_id)
void CPUDevice::execute(WorkPackage *work_package)
{
- const unsigned int chunkNumber = work_package->chunk_number;
- ExecutionGroup *executionGroup = work_package->execution_group;
-
- executionGroup->getOutputOperation()->executeRegion(&work_package->rect, chunkNumber);
- executionGroup->finalizeChunkExecution(chunkNumber, nullptr);
+ switch (work_package->type) {
+ case eWorkPackageType::Tile: {
+ const unsigned int chunkNumber = work_package->chunk_number;
+ ExecutionGroup *executionGroup = work_package->execution_group;
+
+ executionGroup->getOutputOperation()->executeRegion(&work_package->rect, chunkNumber);
+ executionGroup->finalizeChunkExecution(chunkNumber, nullptr);
+ break;
+ }
+ case eWorkPackageType::CustomFunction: {
+ work_package->execute_fn();
+ break;
+ }
+ }
+
+ if (work_package->executed_fn) {
+ work_package->executed_fn();
+ }
}
} // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_CompositorContext.cc b/source/blender/compositor/intern/COM_CompositorContext.cc
index f70f3a8ebfc..61e299c045e 100644
--- a/source/blender/compositor/intern/COM_CompositorContext.cc
+++ b/source/blender/compositor/intern/COM_CompositorContext.cc
@@ -21,6 +21,7 @@
#include <cstdio>
#include "BLI_assert.h"
+#include "DNA_userdef_types.h"
namespace blender::compositor {
@@ -33,6 +34,7 @@ CompositorContext::CompositorContext()
this->m_fastCalculation = false;
this->m_viewSettings = nullptr;
this->m_displaySettings = nullptr;
+ this->m_bnodetree = nullptr;
}
int CompositorContext::getFramenumber() const
@@ -41,4 +43,20 @@ int CompositorContext::getFramenumber() const
return m_rd->cfra;
}
+eExecutionModel CompositorContext::get_execution_model() const
+{
+ if (U.experimental.use_full_frame_compositor) {
+ BLI_assert(m_bnodetree != nullptr);
+ switch (m_bnodetree->execution_mode) {
+ case 1:
+ return eExecutionModel::FullFrame;
+ case 0:
+ return eExecutionModel::Tiled;
+ default:
+ BLI_assert(!"Invalid execution mode");
+ }
+ }
+ return eExecutionModel::Tiled;
+}
+
} // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_CompositorContext.h b/source/b
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list