From 486d200783f3307db4bfb26db3a82044f321f821 Mon Sep 17 00:00:00 2001 From: illua1 Date: Sat, 29 Apr 2023 13:27:26 +0300 Subject: [PATCH 1/5] init --- source/blender/blenkernel/intern/node.cc | 57 ++++++++++++++---------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 364b6635b0d..a85178ccf1f 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -2426,6 +2426,27 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, return node_dst; } +/** + * Type of value storage related with socket is the same. + * \param socket: Node can have multiple sockets & storages pairs. + */ +void **node_static_value_storage_for(bNode &node, const bNodeSocket &socket) +{ + if (!socket.is_output()) { + return nullptr; + } + + switch (node.type) { + case GEO_NODE_IMAGE: { + return reinterpret_cast(&node.id); + } + default: + break; + } + + return nullptr; +} + void node_socket_move_default_value(Main & /*bmain*/, bNodeTree &tree, bNodeSocket &src, @@ -2449,25 +2470,16 @@ void node_socket_move_default_value(Main & /*bmain*/, return; } - ID **src_socket_value = nullptr; - Vector dst_values; + void **src_socket_value = nullptr; + void **dst_value = node_static_value_storage_for(dst_node, dst); + if (dst_value == nullptr) { + return; + } + switch (dst.type) { case SOCK_IMAGE: { Image **tmp_socket_value = &src.default_value_typed()->value; - src_socket_value = reinterpret_cast(tmp_socket_value); - if (*src_socket_value == nullptr) { - break; - } - - switch (dst_node.type) { - case GEO_NODE_IMAGE: { - dst_values.append(&dst_node.id); - break; - } - default: { - break; - } - } + src_socket_value = reinterpret_cast(tmp_socket_value); break; } case SOCK_CUSTOM: @@ -2481,17 +2493,14 @@ void node_socket_move_default_value(Main & /*bmain*/, } } - if (dst_values.is_empty() || src_socket_value == nullptr) { + if (src_socket_value == nullptr) { return; } - for (ID **dst_value : dst_values) { - *dst_value = *src_socket_value; - id_us_plus(*dst_value); - } - - id_us_min(*src_socket_value); - *src_socket_value = nullptr; + ID **src_id = reinterpret_cast(src_socket_value); + ID **dst_id = reinterpret_cast(dst_value); + *dst_id = *src_id; + *src_id = nullptr; } bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, const int flag, const bool use_unique) -- 2.30.2 From 19a7a167e577018d77a532d38bfb78ad07043885 Mon Sep 17 00:00:00 2001 From: illua1 Date: Sat, 29 Apr 2023 21:11:42 +0300 Subject: [PATCH 2/5] init --- source/blender/blenkernel/intern/node.cc | 122 +++++++++++++++++------ 1 file changed, 90 insertions(+), 32 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index a85178ccf1f..a0581fe16d8 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -65,6 +65,7 @@ #include "BKE_node.h" #include "BKE_node_runtime.hh" #include "BKE_node_tree_update.h" +#include "BKE_type_conversions.hh" #include "RNA_access.h" #include "RNA_define.h" @@ -2430,7 +2431,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, * Type of value storage related with socket is the same. * \param socket: Node can have multiple sockets & storages pairs. */ -void **node_static_value_storage_for(bNode &node, const bNodeSocket &socket) +void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) { if (!socket.is_output()) { return nullptr; @@ -2438,7 +2439,19 @@ void **node_static_value_storage_for(bNode &node, const bNodeSocket &socket) switch (node.type) { case GEO_NODE_IMAGE: { - return reinterpret_cast(&node.id); + return &node.id; + } + case FN_NODE_INPUT_VECTOR: { + return &reinterpret_cast(node.storage)->vector; + } + case FN_NODE_INPUT_BOOL: { + return &reinterpret_cast(node.storage)->boolean; + } + case FN_NODE_INPUT_INT: { + return &reinterpret_cast(node.storage)->integer; + } + case FN_NODE_INPUT_COLOR: { + return &reinterpret_cast(node.storage)->color; } default: break; @@ -2447,6 +2460,53 @@ void **node_static_value_storage_for(bNode &node, const bNodeSocket &socket) return nullptr; } +void *socket_value_storage(bNodeSocket &socket) +{ + switch (eNodeSocketDatatype(socket.type)) { + case SOCK_BOOLEAN: { + return &socket.default_value_typed()->value; + } + case SOCK_INT: { + return &socket.default_value_typed()->value; + } + case SOCK_FLOAT: { + return &socket.default_value_typed()->value; + } + case SOCK_VECTOR: { + return &socket.default_value_typed()->value; + } + case SOCK_RGBA: { + return &socket.default_value_typed()->value; + } + case SOCK_IMAGE: { + return &socket.default_value_typed()->value; + } + case SOCK_TEXTURE: { + return &socket.default_value_typed()->value; + } + case SOCK_COLLECTION: { + return &socket.default_value_typed()->value; + } + case SOCK_OBJECT: { + return &socket.default_value_typed()->value; + } + case SOCK_MATERIAL: { + return &socket.default_value_typed()->value; + } + case __SOCK_MESH: + case SOCK_STRING: + case SOCK_CUSTOM: + break; + case SOCK_SHADER: + case SOCK_GEOMETRY: { + /* Unmovable types. */ + break; + } + } + + return nullptr; +} + void node_socket_move_default_value(Main & /*bmain*/, bNodeTree &tree, bNodeSocket &src, @@ -2457,6 +2517,11 @@ void node_socket_move_default_value(Main & /*bmain*/, bNode &dst_node = dst.owner_node(); bNode &src_node = src.owner_node(); + const CPPType &src_type = *src.typeinfo->base_cpp_type; + const CPPType &dst_type = *dst.typeinfo->base_cpp_type; + + const bke::DataTypeConversions &convert = bke::get_implicit_type_conversions(); + if (src.is_multi_input()) { /* Multi input sockets no have value. */ return; @@ -2465,42 +2530,35 @@ void node_socket_move_default_value(Main & /*bmain*/, /* Reroute node can't have ownership of socket value directly. */ return; } - if (dst.type != src.type) { - /* It could be possible to support conversion in future. */ - return; - } - - void **src_socket_value = nullptr; - void **dst_value = node_static_value_storage_for(dst_node, dst); - if (dst_value == nullptr) { - return; - } - - switch (dst.type) { - case SOCK_IMAGE: { - Image **tmp_socket_value = &src.default_value_typed()->value; - src_socket_value = reinterpret_cast(tmp_socket_value); - break; - } - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_GEOMETRY: { - /* Unmovable types. */ + if (&src_type != &dst_type) { + if (!convert.is_convertible(src_type, dst_type)) { return; } - default: { - break; - } } - - if (src_socket_value == nullptr) { + if (eNodeSocketDatatype(src.type) == SOCK_STRING) { + /* We don't want do this now! */ return; } - ID **src_id = reinterpret_cast(src_socket_value); - ID **dst_id = reinterpret_cast(dst_value); - *dst_id = *src_id; - *src_id = nullptr; + void **src_value = static_cast(socket_value_storage(src)); + void **dst_value = static_cast(node_static_value_storage_for(dst_node, dst)); + if (!dst_value || !src_value) { + return; + } + + convert.convert_to_uninitialized(src_type, dst_type, src_value, dst_value); + + src_type.destruct(src_value); + + /* Destruct source value to default value for pointers, strings, and all other. + * + * C++ equivalent: + * src_value = {}; + */ + BUFFER_FOR_CPP_TYPE_VALUE(src_type, src_zero_value); + src_type.value_initialize(src_zero_value); + src_type.copy_assign(src_zero_value, src_value); + src_type.destruct(src_zero_value); } bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, const int flag, const bool use_unique) -- 2.30.2 From 99b5d8082e595b1880dbf4c3a9f5f7b2b40a858e Mon Sep 17 00:00:00 2001 From: illua1 Date: Mon, 1 May 2023 09:18:22 +0300 Subject: [PATCH 3/5] progress --- source/blender/blenkernel/intern/node.cc | 31 +++++++++--------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index a0581fe16d8..5e3a196c6c5 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -2438,21 +2438,21 @@ void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) } switch (node.type) { - case GEO_NODE_IMAGE: { - return &node.id; - } - case FN_NODE_INPUT_VECTOR: { - return &reinterpret_cast(node.storage)->vector; - } case FN_NODE_INPUT_BOOL: { return &reinterpret_cast(node.storage)->boolean; } case FN_NODE_INPUT_INT: { return &reinterpret_cast(node.storage)->integer; } + case FN_NODE_INPUT_VECTOR: { + return &reinterpret_cast(node.storage)->vector; + } case FN_NODE_INPUT_COLOR: { return &reinterpret_cast(node.storage)->color; } + case GEO_NODE_IMAGE: { + return &node.id; + } default: break; } @@ -2493,10 +2493,10 @@ void *socket_value_storage(bNodeSocket &socket) case SOCK_MATERIAL: { return &socket.default_value_typed()->value; } - case __SOCK_MESH: case SOCK_STRING: - case SOCK_CUSTOM: break; + case __SOCK_MESH: + case SOCK_CUSTOM: case SOCK_SHADER: case SOCK_GEOMETRY: { /* Unmovable types. */ @@ -2540,8 +2540,8 @@ void node_socket_move_default_value(Main & /*bmain*/, return; } - void **src_value = static_cast(socket_value_storage(src)); - void **dst_value = static_cast(node_static_value_storage_for(dst_node, dst)); + void *src_value = socket_value_storage(src); + void *dst_value = node_static_value_storage_for(dst_node, dst); if (!dst_value || !src_value) { return; } @@ -2549,16 +2549,7 @@ void node_socket_move_default_value(Main & /*bmain*/, convert.convert_to_uninitialized(src_type, dst_type, src_value, dst_value); src_type.destruct(src_value); - - /* Destruct source value to default value for pointers, strings, and all other. - * - * C++ equivalent: - * src_value = {}; - */ - BUFFER_FOR_CPP_TYPE_VALUE(src_type, src_zero_value); - src_type.value_initialize(src_zero_value); - src_type.copy_assign(src_zero_value, src_value); - src_type.destruct(src_zero_value); + src_type.value_initialize(src_value); } bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, const int flag, const bool use_unique) -- 2.30.2 From f7c3574216acada080f54bab2bc76f71284cdf3b Mon Sep 17 00:00:00 2001 From: illua1 Date: Mon, 1 May 2023 16:42:35 +0300 Subject: [PATCH 4/5] progress --- source/blender/blenkernel/intern/node.cc | 48 ++++++++---------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 5e3a196c6c5..1253978c906 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -2438,21 +2438,16 @@ void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) } switch (node.type) { - case FN_NODE_INPUT_BOOL: { + case FN_NODE_INPUT_BOOL: return &reinterpret_cast(node.storage)->boolean; - } - case FN_NODE_INPUT_INT: { + case FN_NODE_INPUT_INT: return &reinterpret_cast(node.storage)->integer; - } - case FN_NODE_INPUT_VECTOR: { + case FN_NODE_INPUT_VECTOR: return &reinterpret_cast(node.storage)->vector; - } - case FN_NODE_INPUT_COLOR: { + case FN_NODE_INPUT_COLOR: return &reinterpret_cast(node.storage)->color; - } - case GEO_NODE_IMAGE: { + case GEO_NODE_IMAGE: return &node.id; - } default: break; } @@ -2463,45 +2458,34 @@ void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) void *socket_value_storage(bNodeSocket &socket) { switch (eNodeSocketDatatype(socket.type)) { - case SOCK_BOOLEAN: { + case SOCK_BOOLEAN: return &socket.default_value_typed()->value; - } - case SOCK_INT: { + case SOCK_INT: return &socket.default_value_typed()->value; - } - case SOCK_FLOAT: { + case SOCK_FLOAT: return &socket.default_value_typed()->value; - } - case SOCK_VECTOR: { + case SOCK_VECTOR: return &socket.default_value_typed()->value; - } - case SOCK_RGBA: { + case SOCK_RGBA: return &socket.default_value_typed()->value; - } - case SOCK_IMAGE: { + case SOCK_IMAGE: return &socket.default_value_typed()->value; - } - case SOCK_TEXTURE: { + case SOCK_TEXTURE: return &socket.default_value_typed()->value; - } - case SOCK_COLLECTION: { + case SOCK_COLLECTION: return &socket.default_value_typed()->value; - } - case SOCK_OBJECT: { + case SOCK_OBJECT: return &socket.default_value_typed()->value; - } - case SOCK_MATERIAL: { + case SOCK_MATERIAL: return &socket.default_value_typed()->value; - } case SOCK_STRING: break; case __SOCK_MESH: case SOCK_CUSTOM: case SOCK_SHADER: - case SOCK_GEOMETRY: { + case SOCK_GEOMETRY: /* Unmovable types. */ break; - } } return nullptr; -- 2.30.2 From 7fd4323a4ce622e58197f3e19341072f7ddcdcfc Mon Sep 17 00:00:00 2001 From: illua1 Date: Tue, 2 May 2023 00:00:56 +0300 Subject: [PATCH 5/5] progress --- source/blender/blenkernel/intern/node.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 1253978c906..5608ad626b5 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -2431,7 +2431,7 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree, * Type of value storage related with socket is the same. * \param socket: Node can have multiple sockets & storages pairs. */ -void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) +static void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) { if (!socket.is_output()) { return nullptr; @@ -2455,7 +2455,7 @@ void *node_static_value_storage_for(bNode &node, const bNodeSocket &socket) return nullptr; } -void *socket_value_storage(bNodeSocket &socket) +static void *socket_value_storage(bNodeSocket &socket) { switch (eNodeSocketDatatype(socket.type)) { case SOCK_BOOLEAN: @@ -2479,7 +2479,8 @@ void *socket_value_storage(bNodeSocket &socket) case SOCK_MATERIAL: return &socket.default_value_typed()->value; case SOCK_STRING: - break; + /* We don't want do this now! */ + return nullptr; case __SOCK_MESH: case SOCK_CUSTOM: case SOCK_SHADER: @@ -2519,10 +2520,6 @@ void node_socket_move_default_value(Main & /*bmain*/, return; } } - if (eNodeSocketDatatype(src.type) == SOCK_STRING) { - /* We don't want do this now! */ - return; - } void *src_value = socket_value_storage(src); void *dst_value = node_static_value_storage_for(dst_node, dst); @@ -2533,7 +2530,14 @@ void node_socket_move_default_value(Main & /*bmain*/, convert.convert_to_uninitialized(src_type, dst_type, src_value, dst_value); src_type.destruct(src_value); - src_type.value_initialize(src_value); + if (ELEM(eNodeSocketDatatype(src.type), + SOCK_COLLECTION, + SOCK_IMAGE, + SOCK_MATERIAL, + SOCK_TEXTURE, + SOCK_OBJECT)) { + src_type.value_initialize(src_value); + } } bNode *node_copy(bNodeTree *dst_tree, const bNode &src_node, const int flag, const bool use_unique) -- 2.30.2