Blender V5.0
COM_shader_node.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_string_ref.hh"
8#include "BLI_vector.hh"
9
10#include "DNA_node_types.h"
11
12#include "GPU_material.hh"
13
15
16namespace blender::compositor {
17
18using namespace nodes::derived_node_tree_types;
19
20/* ------------------------------------------------------------------------------------------------
21 * Shader Node
22 *
23 * A shader node encapsulates a compositor node tree that is capable of being used together with
24 * other shader nodes to construct a Shader Operation using the GPU material compiler. A GPU node
25 * stack for each of the node inputs and outputs is stored and populated during construction in
26 * order to represent the node as a GPU node inside the GPU material graph, see GPU_material.hh for
27 * more information. The compiler is expected to initialize the input links of the node inputs
28 * before invoking the compile method. See the discussion in COM_shader_operation.hh for more
29 * information. */
31 private:
32 /* The node that this operation represents. */
33 DNode node_;
34 /* The GPU node stacks of the inputs of the node. Those are populated during construction in the
35 * populate_inputs method. The links of the inputs are initialized by the GPU material compiler
36 * prior to calling the compile method. There is an extra stack at the end to mark the end of the
37 * array, as this is what the GPU module functions expect. */
39 /* The GPU node stacks of the outputs of the node. Those are populated during construction in the
40 * populate_outputs method. There is an extra stack at the end to mark the end of the array, as
41 * this is what the GPU module functions expect. */
42 Vector<GPUNodeStack> outputs_;
43
44 public:
45 /* Construct the node by populating both its inputs and outputs. */
46 ShaderNode(DNode node);
47
48 /* Compile the node by adding the appropriate GPU material graph nodes and linking the
49 * appropriate resources. */
50 void compile(GPUMaterial *material);
51
52 /* Returns the GPU node stack of the input with the given identifier. */
53 GPUNodeStack &get_input(StringRef identifier);
54
55 /* Returns the GPU node stack of the output with the given identifier. */
57
58 private:
59 /* Populate the inputs of the node. The input link is set to nullptr and is expected to be
60 * initialized by the GPU material compiler before calling the compile method. */
61 void populate_inputs();
62 /* Populate the outputs of the node. The output link is set to nullptr and is expected to be
63 * initialized by the compile method. */
64 void populate_outputs();
65};
66
67} // namespace blender::compositor
GPUNodeStack & get_input(StringRef identifier)
void compile(GPUMaterial *material)
GPUNodeStack & get_output(StringRef identifier)