Blender  V3.3
multi_function_builder.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
4 
5 #include "BLI_hash.hh"
6 
7 namespace blender::fn {
8 
10  const void *value,
11  bool make_value_copy)
12  : type_(type), owns_value_(make_value_copy)
13 {
14  if (make_value_copy) {
15  void *copied_value = MEM_mallocN_aligned(type.size(), type.alignment(), __func__);
16  type.copy_construct(value, copied_value);
17  value = copied_value;
18  }
19  value_ = value;
20 
21  MFSignatureBuilder signature{"Constant"};
22  signature.single_output("Value", type);
23  signature_ = signature.build();
24  this->set_signature(&signature_);
25 }
26 
28 {
29  if (owns_value_) {
30  signature_.param_types[0].data_type().single_type().destruct((void *)value_);
31  MEM_freeN((void *)value_);
32  }
33 }
34 
37  MFContext UNUSED(context)) const
38 {
39  GMutableSpan output = params.uninitialized_single_output(0);
40  type_.fill_construct_indices(value_, output.data(), mask);
41 }
42 
44 {
45  return type_.hash_or_fallback(value_, (uintptr_t)this);
46 }
47 
49 {
50  const CustomMF_GenericConstant *_other = dynamic_cast<const CustomMF_GenericConstant *>(&other);
51  if (_other == nullptr) {
52  return false;
53  }
54  if (type_ != _other->type_) {
55  return false;
56  }
57  return type_.is_equal(value_, _other->value_);
58 }
59 
61 {
62  const CPPType &type = array.type();
63  MFSignatureBuilder signature{"Constant Vector"};
64  signature.vector_output("Value", type);
65  signature_ = signature.build();
66  this->set_signature(&signature_);
67 }
68 
71  MFContext UNUSED(context)) const
72 {
73  GVectorArray &vectors = params.vector_output(0);
74  for (int64_t i : mask) {
75  vectors.extend(i, array_);
76  }
77 }
78 
80  Span<MFDataType> output_types)
81  : output_amount_(output_types.size())
82 {
83  MFSignatureBuilder signature{"Default Output"};
84  for (MFDataType data_type : input_types) {
85  signature.input("Input", data_type);
86  }
87  for (MFDataType data_type : output_types) {
88  signature.output("Output", data_type);
89  }
90  signature_ = signature.build();
91  this->set_signature(&signature_);
92 }
94 {
95  for (int param_index : this->param_indices()) {
96  MFParamType param_type = this->param_type(param_index);
97  if (!param_type.is_output()) {
98  continue;
99  }
100 
101  if (param_type.data_type().is_single()) {
102  GMutableSpan span = params.uninitialized_single_output(param_index);
103  const CPPType &type = span.type();
104  type.fill_construct_indices(type.default_value(), span.data(), mask);
105  }
106  }
107 }
108 
110 {
112  signature.input("Input", data_type);
113  signature.output("Output", data_type);
114  signature_ = signature.build();
115  this->set_signature(&signature_);
116 }
117 
119 {
120  const MFDataType data_type = this->param_type(0).data_type();
121  switch (data_type.category()) {
122  case MFDataType::Single: {
123  const GVArray &inputs = params.readonly_single_input(0, "Input");
124  GMutableSpan outputs = params.uninitialized_single_output(1, "Output");
125  inputs.materialize_to_uninitialized(mask, outputs.data());
126  break;
127  }
128  case MFDataType::Vector: {
129  const GVVectorArray &inputs = params.readonly_vector_input(0, "Input");
130  GVectorArray &outputs = params.vector_output(1, "Output");
131  outputs.extend(mask, inputs);
132  break;
133  }
134  }
135 }
136 
137 } // namespace blender::fn
#define UNUSED(x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
uint64_t hash_or_fallback(const void *value, uint64_t fallback_hash) const
bool is_equal(const void *a, const void *b) const
void fill_construct_indices(const void *value, void *dst, IndexMask mask) const
const CPPType & type() const
void extend(int64_t index, const GVArray &values)
void call(IndexMask mask, MFParams params, MFContext context) const override
CustomMF_DefaultOutput(Span< MFDataType > input_types, Span< MFDataType > output_types)
void call(IndexMask mask, MFParams params, MFContext context) const override
CustomMF_GenericConstant(const CPPType &type, const void *value, bool make_value_copy)
void call(IndexMask mask, MFParams params, MFContext context) const override
bool equals(const MultiFunction &other) const override
void call(IndexMask mask, MFParams params, MFContext context) const override
MFParamType param_type(int param_index) const
IndexRange param_indices() const
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_global KernelShaderEvalInput ccl_global float * output
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN_aligned)(size_t len, size_t alignment, const char *str)
Definition: mallocn.c:35
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static bNodeSocketTemplate outputs[]
static bNodeSocketTemplate inputs[]
_W64 unsigned int uintptr_t
Definition: stdint.h:119
__int64 int64_t
Definition: stdint.h:89
unsigned __int64 uint64_t
Definition: stdint.h:90