[Bf-blender-cvs] [624b0ac656e] master: Realtime Compositor: Add evaluator and engine

Omar Emara noreply at git.blender.org
Wed Aug 10 09:17:01 CEST 2022


Commit: 624b0ac656e4876c8518adb479be94e581c46bb8
Author: Omar Emara
Date:   Wed Aug 10 09:14:22 2022 +0200
Branches: master
https://developer.blender.org/rB624b0ac656e4876c8518adb479be94e581c46bb8

Realtime Compositor: Add evaluator and engine

This patch adds the core realtime compositor evaluator as well as a
compositor draw engine powered by the evaluator that operates in the
viewport. The realtime compositor is a new GPU accelerated compositor
that will be used to power the viewport compositor imminently as well as
the existing compositor in the future.

This patch only adds the evaluator and engine as an experimental
feature, the implementation of the nodes themselves will be committed
separately.

See T99210.

Differential Revision: https://developer.blender.org/D15206

Reviewed By: Clement Foucault

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/compositor/CMakeLists.txt
A	source/blender/compositor/realtime_compositor/CMakeLists.txt
A	source/blender/compositor/realtime_compositor/COM_compile_state.hh
A	source/blender/compositor/realtime_compositor/COM_context.hh
A	source/blender/compositor/realtime_compositor/COM_conversion_operation.hh
A	source/blender/compositor/realtime_compositor/COM_domain.hh
A	source/blender/compositor/realtime_compositor/COM_evaluator.hh
A	source/blender/compositor/realtime_compositor/COM_input_descriptor.hh
A	source/blender/compositor/realtime_compositor/COM_input_single_value_operation.hh
A	source/blender/compositor/realtime_compositor/COM_node_operation.hh
A	source/blender/compositor/realtime_compositor/COM_operation.hh
A	source/blender/compositor/realtime_compositor/COM_realize_on_domain_operation.hh
A	source/blender/compositor/realtime_compositor/COM_reduce_to_single_value_operation.hh
A	source/blender/compositor/realtime_compositor/COM_result.hh
A	source/blender/compositor/realtime_compositor/COM_scheduler.hh
A	source/blender/compositor/realtime_compositor/COM_shader_node.hh
A	source/blender/compositor/realtime_compositor/COM_shader_operation.hh
A	source/blender/compositor/realtime_compositor/COM_simple_operation.hh
A	source/blender/compositor/realtime_compositor/COM_static_shader_manager.hh
A	source/blender/compositor/realtime_compositor/COM_texture_pool.hh
A	source/blender/compositor/realtime_compositor/COM_utilities.hh
A	source/blender/compositor/realtime_compositor/intern/compile_state.cc
A	source/blender/compositor/realtime_compositor/intern/context.cc
A	source/blender/compositor/realtime_compositor/intern/conversion_operation.cc
A	source/blender/compositor/realtime_compositor/intern/domain.cc
A	source/blender/compositor/realtime_compositor/intern/evaluator.cc
A	source/blender/compositor/realtime_compositor/intern/input_single_value_operation.cc
A	source/blender/compositor/realtime_compositor/intern/node_operation.cc
A	source/blender/compositor/realtime_compositor/intern/operation.cc
A	source/blender/compositor/realtime_compositor/intern/realize_on_domain_operation.cc
A	source/blender/compositor/realtime_compositor/intern/reduce_to_single_value_operation.cc
A	source/blender/compositor/realtime_compositor/intern/result.cc
A	source/blender/compositor/realtime_compositor/intern/scheduler.cc
A	source/blender/compositor/realtime_compositor/intern/shader_node.cc
A	source/blender/compositor/realtime_compositor/intern/shader_operation.cc
A	source/blender/compositor/realtime_compositor/intern/simple_operation.cc
A	source/blender/compositor/realtime_compositor/intern/static_shader_manager.cc
A	source/blender/compositor/realtime_compositor/intern/texture_pool.cc
A	source/blender/compositor/realtime_compositor/intern/utilities.cc
M	source/blender/draw/CMakeLists.txt
A	source/blender/draw/engines/compositor/compositor_engine.cc
A	source/blender/draw/engines/compositor/compositor_engine.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/gpu/CMakeLists.txt
A	source/blender/gpu/shaders/compositor/compositor_convert.glsl
A	source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
A	source/blender/gpu/shaders/compositor/infos/compositor_convert_info.hh
A	source/blender/gpu/shaders/compositor/infos/compositor_realize_on_domain_info.hh
A	source/blender/gpu/shaders/compositor/library/gpu_shader_compositor_main.glsl
A	source/blender/gpu/shaders/compositor/library/gpu_shader_compositor_store_output.glsl
A	source/blender/gpu/shaders/compositor/library/gpu_shader_compositor_texture_utilities.glsl
A	source/blender/gpu/shaders/compositor/library/gpu_shader_compositor_type_conversion.glsl
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/nodes/NOD_node_declaration.hh

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 52b2fb7f3da..2085ecaf74d 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -2258,6 +2258,7 @@ class USERPREF_PT_experimental_new_features(ExperimentalPanel, Panel):
                 ({"property": "use_sculpt_tools_tilt"}, "T82877"),
                 ({"property": "use_extended_asset_browser"}, ("project/view/130/", "Project Page")),
                 ({"property": "use_override_templates"}, ("T73318", "Milestone 4")),
+                ({"property": "use_realtime_compositor"}, "T99210"),
             ),
         )
 
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 2f9050ba638..299518935ef 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6128,6 +6128,24 @@ class VIEW3D_PT_shading_render_pass(Panel):
         layout.prop(shading, "render_pass", text="")
 
 
+class VIEW3D_PT_shading_compositor(Panel):
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'HEADER'
+    bl_label = "Compositor"
+    bl_parent_id = 'VIEW3D_PT_shading'
+
+    @classmethod
+    def poll(cls, context):
+        return (context.space_data.shading.type in ('MATERIAL', 'RENDERED') and
+                context.preferences.experimental.use_realtime_compositor)
+
+    def draw(self, context):
+        shading = context.space_data.shading
+
+        layout = self.layout
+        layout.prop(shading, "use_compositor")
+
+
 class VIEW3D_PT_gizmo_display(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'HEADER'
@@ -7967,6 +7985,7 @@ classes = (
     VIEW3D_PT_shading_options_shadow,
     VIEW3D_PT_shading_options_ssao,
     VIEW3D_PT_shading_render_pass,
+    VIEW3D_PT_shading_compositor,
     VIEW3D_PT_gizmo_display,
     VIEW3D_PT_overlay,
     VIEW3D_PT_overlay_guides,
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 02e3cefe6a5..b42b9df510d 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -101,6 +101,7 @@ typedef struct bNodeSocketTemplate {
 namespace blender {
 class CPPType;
 namespace nodes {
+class DNode;
 class NodeMultiFunctionBuilder;
 class GeoNodeExecParams;
 class NodeDeclarationBuilder;
@@ -109,6 +110,11 @@ class GatherLinkSearchOpParams;
 namespace fn {
 class MFDataType;
 }  // namespace fn
+namespace realtime_compositor {
+class Context;
+class NodeOperation;
+class ShaderNode;
+}  // namespace realtime_compositor
 }  // namespace blender
 
 using CPPTypeHandle = blender::CPPType;
@@ -123,7 +129,14 @@ using SocketGetGeometryNodesCPPValueFunction = void (*)(const struct bNodeSocket
 using NodeGatherSocketLinkOperationsFunction =
     void (*)(blender::nodes::GatherLinkSearchOpParams &params);
 
+using NodeGetCompositorOperationFunction = blender::realtime_compositor::NodeOperation
+    *(*)(blender::realtime_compositor::Context &context, blender::nodes::DNode node);
+using NodeGetCompositorShaderNodeFunction =
+    blender::realtime_compositor::ShaderNode *(*)(blender::nodes::DNode node);
+
 #else
+typedef void *NodeGetCompositorOperationFunction;
+typedef void *NodeGetCompositorShaderNodeFunction;
 typedef void *NodeMultiFunctionBuildFunction;
 typedef void *NodeGeometryExecFunction;
 typedef void *NodeDeclareFunction;
@@ -309,6 +322,14 @@ typedef struct bNodeType {
   /* gpu */
   NodeGPUExecFunction gpu_fn;
 
+  /* Get an instance of this node's compositor operation. Freeing the instance is the
+   * responsibility of the caller. */
+  NodeGetCompositorOperationFunction get_compositor_operation;
+
+  /* Get an instance of this node's compositor shader node. Freeing the instance is the
+   * responsibility of the caller. */
+  NodeGetCompositorShaderNodeFunction get_compositor_shader_node;
+
   /* Build a multi-function for this node. */
   NodeMultiFunctionBuildFunction build_multi_function;
 
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index c555dbafbc5..f49a9694ab3 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -1,8 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright 2011 Blender Foundation. All rights reserved.
 
-if(WITH_COMPOSITOR_CPU)
+add_subdirectory(realtime_compositor)
 
+if(WITH_COMPOSITOR_CPU)
   set(INC
     .
     intern
diff --git a/source/blender/compositor/realtime_compositor/CMakeLists.txt b/source/blender/compositor/realtime_compositor/CMakeLists.txt
new file mode 100644
index 00000000000..9fe156c3ef2
--- /dev/null
+++ b/source/blender/compositor/realtime_compositor/CMakeLists.txt
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set(INC
+  .
+  ../../gpu
+  ../../nodes
+  ../../imbuf
+  ../../blenlib
+  ../../makesdna
+  ../../makesrna
+  ../../blenkernel
+  ../../gpu/intern
+  ../../../../intern/guardedalloc
+)
+
+
+set(SRC
+  intern/compile_state.cc
+  intern/context.cc
+  intern/conversion_operation.cc
+  intern/domain.cc
+  intern/evaluator.cc
+  intern/input_single_value_operation.cc
+  intern/node_operation.cc
+  intern/operation.cc
+  intern/realize_on_domain_operation.cc
+  intern/reduce_to_single_value_operation.cc
+  intern/result.cc
+  intern/scheduler.cc
+  intern/shader_node.cc
+  intern/shader_operation.cc
+  intern/simple_operation.cc
+  intern/static_shader_manager.cc
+  intern/texture_pool.cc
+  intern/utilities.cc
+
+  COM_compile_state.hh
+  COM_context.hh
+  COM_conversion_operation.hh
+  COM_domain.hh
+  COM_evaluator.hh
+  COM_input_descriptor.hh
+  COM_input_single_value_operation.hh
+  COM_node_operation.hh
+  COM_operation.hh
+  COM_realize_on_domain_operation.hh
+  COM_reduce_to_single_value_operation.hh
+  COM_result.hh
+  COM_scheduler.hh
+  COM_shader_node.hh
+  COM_shader_operation.hh
+  COM_simple_operation.hh
+  COM_static_shader_manager.hh
+  COM_texture_pool.hh
+  COM_utilities.hh
+)
+
+set(LIB
+  bf_gpu
+  bf_nodes
+  bf_imbuf
+  bf_blenlib
+  bf_blenkernel
+)
+
+blender_add_lib(bf_realtime_compositor "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/compositor/realtime_compositor/COM_compile_state.hh b/source/blender/compositor/realtime_compositor/COM_compile_state.hh
new file mode 100644
index 00000000000..ed6ad414e3b
--- /dev/null
+++ b/source/blender/compositor/realtime_compositor/COM_compile_state.hh
@@ -0,0 +1,170 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+#include "BLI_map.hh"
+
+#include "NOD_derived_node_tree.hh"
+
+#include "COM_domain.hh"
+#include "COM_node_operation.hh"
+#include "COM_scheduler.hh"
+#include "COM_shader_operation.hh"
+
+namespace blender::realtime_compositor {
+
+using namespace nodes::derived_node_tree_types;
+
+/* ------------------------------------------------------------------------------------------------
+ * Compile State
+ *
+ * The compile state is a utility class used to track the state of compilation when compiling the
+ * node tree. In particular, it tracks two important pieces of information, each of which is
+ * described in one of the following sections.
+ *
+ * First, it stores a mapping between all nodes and the operations they were compiled into. The
+ * mapping are stored independently depending on the type of the operation in the node_operations_
+ * and shader_operations_ maps. So those two maps are mutually exclusive. The compiler should call
+ * the map_node_to_node_operation and map_node_to_shader_operation methods to populate those maps
+ * as soon as it compiles a node or multiple nodes into an operation. Those maps are used to
+ * retrieve the results of outputs linked to the inputs of operations. For more details, see the
+ * get_result_from_output_socket method. For the node tree shown below, nodes 1, 2, and 6 are
+ * mapped to their compiled operations in the node_operation_ map. While nodes 3 and 4 are both
+ * mapped to the first shader operation, and node 5 is mapped to the second shader operation in the
+ * shader_operations_ map.
+ *
+ *                             Shader Operation 1               Shader Operation 2
+ *                   +-----------------------------------+     +------------------+
+ * .------------.    |  .------------.  .------------.   |     |  .------------.  |  .------------.
+ * |   Node 1   |    |  |   Node 3   |  |   Node 4   |   |     |  |   Node 5   |  |  |   Node 6   |
+ * |            |----|--|            |--|            |---|-----|--|            |--|--|            |
+ * |            |  .-|--|            |  |            |   |  .--|--|            |  |  |            |
+ * '------------'  | |  '------------'  '------------'   |  |  |  '------------'  |  '------------'
+ *                 | +-----------------------------------+  |  +------------------+
+ * .------------.  |                                        |
+ * |   Node 2   |  |                                        |
+ * |            |--'----------------------------------------'
+ * |            |
+ * '------------'
+ *
+ * Second, it stores the shader compile unit as well as its domain. One should first go over the
+ * discussion in COM_evaluator.hh for a high level description of the mechanism of the compile
+ * unit. The one important detail in this class is the should_compile_shader_compile_unit method,
+ * which implements the criteria of whether the compile unit should be compiled given the node
+ * currently being processed as an argument. Those criteria are described as follows. If the
+ * compile unit is empty as is the case when processing nodes 1, 2, and 3, then it plainly
+ * shouldn't be compiled. If the given node is not a shader node, then it can't be added to the
+ * compile unit and the unit is considered complete and should be compiled, as is the case when
+ * processing node 6. If the computed domain of the given node is not compatible with the domain of
+ * the compiled unit, then it can't be added to the unit and the unit is considered complete and
+ * should be compiled, as is the case when processing node 5, more on this in the next section.
+ 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list