Blender V4.3
compute_contexts.cc
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#include "DNA_node_types.h"
6
8
9#include <ostream>
10
11namespace blender::bke {
12
14 std::string modifier_name)
15 : ComputeContext(s_static_type, parent), modifier_name_(std::move(modifier_name))
16{
17 hash_.mix_in(s_static_type, strlen(s_static_type));
18 hash_.mix_in(modifier_name_.data(), modifier_name_.size());
19}
20
21void ModifierComputeContext::print_current_in_line(std::ostream &stream) const
22{
23 stream << "Modifier: " << modifier_name_;
24}
25
27 const ComputeContext *parent,
28 const int32_t node_id,
29 const std::optional<ComputeContextHash> &cached_hash)
30 : ComputeContext(s_static_type, parent), node_id_(node_id)
31{
32 if (cached_hash.has_value()) {
33 hash_ = *cached_hash;
34 }
35 else {
36 /* Mix static type and node id into a single buffer so that only a single call to #mix_in is
37 * necessary. */
38 const int type_size = strlen(s_static_type);
39 const int buffer_size = type_size + 1 + sizeof(int32_t);
40 DynamicStackBuffer<64, 8> buffer_owner(buffer_size, 8);
41 char *buffer = static_cast<char *>(buffer_owner.buffer());
42 memcpy(buffer, s_static_type, type_size + 1);
43 memcpy(buffer + type_size + 1, &node_id_, sizeof(int32_t));
44 hash_.mix_in(buffer, buffer_size);
45 }
46}
47
49 const bNode &node,
50 const bNodeTree &caller_tree)
51 : GroupNodeComputeContext(parent, node.identifier)
52{
53 caller_group_node_ = &node;
54 caller_tree_ = &caller_tree;
55}
56
57void GroupNodeComputeContext::print_current_in_line(std::ostream &stream) const
58{
59 if (caller_group_node_ != nullptr) {
60 stream << "Node: " << caller_group_node_->name;
61 return;
62 }
63}
64
66 const int32_t output_node_id)
67 : ComputeContext(s_static_type, parent), output_node_id_(output_node_id)
68{
69 /* Mix static type and node id into a single buffer so that only a single call to #mix_in is
70 * necessary. */
71 const int type_size = strlen(s_static_type);
72 const int buffer_size = type_size + 1 + sizeof(int32_t);
73 DynamicStackBuffer<64, 8> buffer_owner(buffer_size, 8);
74 char *buffer = static_cast<char *>(buffer_owner.buffer());
75 memcpy(buffer, s_static_type, type_size + 1);
76 memcpy(buffer + type_size + 1, &output_node_id_, sizeof(int32_t));
77 hash_.mix_in(buffer, buffer_size);
78}
79
81 const bNode &node)
82 : SimulationZoneComputeContext(parent, node.identifier)
83{
84}
85
86void SimulationZoneComputeContext::print_current_in_line(std::ostream &stream) const
87{
88 stream << "Simulation Zone ID: " << output_node_id_;
89}
90
92 const int32_t output_node_id,
93 const int iteration)
94 : ComputeContext(s_static_type, parent), output_node_id_(output_node_id), iteration_(iteration)
95{
96 /* Mix static type and node id into a single buffer so that only a single call to #mix_in is
97 * necessary. */
98 const int type_size = strlen(s_static_type);
99 const int buffer_size = type_size + 1 + sizeof(int32_t) + sizeof(int);
100 DynamicStackBuffer<64, 8> buffer_owner(buffer_size, 8);
101 char *buffer = static_cast<char *>(buffer_owner.buffer());
102 memcpy(buffer, s_static_type, type_size + 1);
103 memcpy(buffer + type_size + 1, &output_node_id_, sizeof(int32_t));
104 memcpy(buffer + type_size + 1 + sizeof(int32_t), &iteration_, sizeof(int));
105 hash_.mix_in(buffer, buffer_size);
106}
107
109 const bNode &node,
110 const int iteration)
111 : RepeatZoneComputeContext(parent, node.identifier, iteration)
112{
113}
114
115void RepeatZoneComputeContext::print_current_in_line(std::ostream &stream) const
116{
117 stream << "Repeat Zone ID: " << output_node_id_;
118}
119
121 const ComputeContext *parent, const int32_t output_node_id, const int index)
122 : ComputeContext(s_static_type, parent), output_node_id_(output_node_id), index_(index)
123{
124 /* Mix static type and node id into a single buffer so that only a single call to #mix_in is
125 * necessary. */
126 const int type_size = strlen(s_static_type);
127 const int buffer_size = type_size + 1 + sizeof(int32_t) + sizeof(int);
128 DynamicStackBuffer<64, 8> buffer_owner(buffer_size, 8);
129 char *buffer = static_cast<char *>(buffer_owner.buffer());
130 memcpy(buffer, s_static_type, type_size + 1);
131 memcpy(buffer + type_size + 1, &output_node_id_, sizeof(int32_t));
132 memcpy(buffer + type_size + 1 + sizeof(int32_t), &index_, sizeof(int));
133 hash_.mix_in(buffer, buffer_size);
134}
135
137 const ComputeContext *parent, const bNode &node, const int index)
138 : ForeachGeometryElementZoneComputeContext(parent, node.identifier, index)
139{
140}
141
142void ForeachGeometryElementZoneComputeContext::print_current_in_line(std::ostream &stream) const
143{
144 stream << "Foreach Geometry Element Zone ID: " << output_node_id_;
145}
146
148
150 : ComputeContext(s_static_type, parent)
151{
152 hash_.mix_in(s_static_type, strlen(s_static_type));
153}
154
155void OperatorComputeContext::print_current_in_line(std::ostream &stream) const
156{
157 stream << "Operator";
158}
159
160} // namespace blender::bke
ForeachGeometryElementZoneComputeContext(const ComputeContext *parent, int32_t output_node_id, int index)
GroupNodeComputeContext(const ComputeContext *parent, int32_t node_id, const std::optional< ComputeContextHash > &cached_hash={})
ModifierComputeContext(const ComputeContext *parent, std::string modifier_name)
RepeatZoneComputeContext(const ComputeContext *parent, int32_t output_node_id, int iteration)
SimulationZoneComputeContext(const ComputeContext *parent, int output_node_id)
OperationNode * node
static const char * modifier_name[LS_MODIFIER_NUM]
Definition linestyle.cc:680
signed int int32_t
Definition stdint.h:77
char name[64]
void mix_in(const void *data, int64_t len)