diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh index a9e1bed2701..8d9a753bc0a 100644 --- a/source/blender/blenkernel/BKE_node_runtime.hh +++ b/source/blender/blenkernel/BKE_node_runtime.hh @@ -814,28 +814,28 @@ inline const bNodeSocket &bNode::output_socket(int index) const return *this->runtime->outputs[index]; } -inline const bNodeSocket &bNode::input_by_identifier(blender::StringRef identifier) const +inline const bNodeSocket *bNode::input_by_identifier(blender::StringRef identifier) const { BLI_assert(blender::bke::node_tree_runtime::topology_cache_is_available(*this)); - return *this->runtime->inputs_by_identifier.lookup_as(identifier); + return this->runtime->inputs_by_identifier.lookup_default_as(identifier, nullptr); } -inline const bNodeSocket &bNode::output_by_identifier(blender::StringRef identifier) const +inline const bNodeSocket *bNode::output_by_identifier(blender::StringRef identifier) const { BLI_assert(blender::bke::node_tree_runtime::topology_cache_is_available(*this)); - return *this->runtime->outputs_by_identifier.lookup_as(identifier); + return this->runtime->outputs_by_identifier.lookup_default_as(identifier, nullptr); } -inline bNodeSocket &bNode::input_by_identifier(blender::StringRef identifier) +inline bNodeSocket *bNode::input_by_identifier(blender::StringRef identifier) { BLI_assert(blender::bke::node_tree_runtime::topology_cache_is_available(*this)); - return *this->runtime->inputs_by_identifier.lookup_as(identifier); + return this->runtime->inputs_by_identifier.lookup_default_as(identifier, nullptr); } -inline bNodeSocket &bNode::output_by_identifier(blender::StringRef identifier) +inline bNodeSocket *bNode::output_by_identifier(blender::StringRef identifier) { BLI_assert(blender::bke::node_tree_runtime::topology_cache_is_available(*this)); - return *this->runtime->outputs_by_identifier.lookup_as(identifier); + return this->runtime->outputs_by_identifier.lookup_default_as(identifier, nullptr); } inline const bNodeTree &bNode::owner_tree() const diff --git a/source/blender/compositor/utilities/intern/gpu_material.cc b/source/blender/compositor/utilities/intern/gpu_material.cc index bb1580106bc..5203dbd9493 100644 --- a/source/blender/compositor/utilities/intern/gpu_material.cc +++ b/source/blender/compositor/utilities/intern/gpu_material.cc @@ -18,14 +18,14 @@ GPUNodeStack &get_shader_node_input(const bNode &node, GPUNodeStack inputs[], const StringRef identifier) { - return inputs[node.input_by_identifier(identifier).index()]; + return inputs[node.input_by_identifier(identifier)->index()]; } GPUNodeStack &get_shader_node_output(const bNode &node, GPUNodeStack outputs[], const StringRef identifier) { - return outputs[node.output_by_identifier(identifier).index()]; + return outputs[node.output_by_identifier(identifier)->index()]; } GPUNodeLink *get_shader_node_input_link(const bNode &node, diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc index d34209d5a06..a77a661b102 100644 --- a/source/blender/editors/space_node/node_add.cc +++ b/source/blender/editors/space_node/node_add.cc @@ -1092,7 +1092,7 @@ static wmOperatorStatus node_add_import_node_exec(bContext *C, wmOperator *op) } if (node) { - bNodeSocket &path_socket = node->input_by_identifier("Path"); + bNodeSocket &path_socket = *node->input_by_identifier("Path"); BLI_assert(path_socket.type == SOCK_STRING); auto *socket_data = static_cast(path_socket.default_value); STRNCPY(socket_data->value, path.c_str()); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_geometry_nodes.cc b/source/blender/editors/space_view3d/view3d_gizmo_geometry_nodes.cc index ae2268a2f97..bc1068ded1b 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_geometry_nodes.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_geometry_nodes.cc @@ -128,7 +128,7 @@ struct GizmosUpdateParams { template [[nodiscard]] bool get_input_value(const StringRef identifier, T &r_value) { - const bNodeSocket &socket = this->gizmo_node.input_by_identifier(identifier); + const bNodeSocket &socket = *this->gizmo_node.input_by_identifier(identifier); const std::optional value_opt = this->tree_log.find_primitive_socket_value(socket); if (!value_opt) { return false; @@ -1056,7 +1056,7 @@ static void WIDGETGROUP_geometry_nodes_refresh(const bContext *C, wmGizmoGroup * const StringRef socket_identifier, const FunctionRef modify_value) { gizmo_node_tree->ensure_topology_cache(); - const bNodeSocket &socket = gizmo_node->input_by_identifier(socket_identifier); + const bNodeSocket &socket = *gizmo_node->input_by_identifier(socket_identifier); nodes::gizmos::apply_gizmo_change(*const_cast(C), const_cast(*object_orig), diff --git a/source/blender/io/usd/hydra/world.cc b/source/blender/io/usd/hydra/world.cc index b5246f4391a..b8933b70925 100644 --- a/source/blender/io/usd/hydra/world.cc +++ b/source/blender/io/usd/hydra/world.cc @@ -82,8 +82,8 @@ void WorldData::init() return; } - const bNodeSocket &color_input = input_node->input_by_identifier("Color"); - const bNodeSocket &strength_input = input_node->input_by_identifier("Strength"); + const bNodeSocket &color_input = *input_node->input_by_identifier("Color"); + const bNodeSocket &strength_input = *input_node->input_by_identifier("Strength"); float const *strength = strength_input.default_value_typed(); float const *input_color = color_input.default_value_typed(); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index d63d260eba9..18e60d4a93c 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -575,10 +575,10 @@ typedef struct bNode { bNodeSocket &output_socket(int index); const bNodeSocket &output_socket(int index) const; /** Lookup socket of this node by its identifier. */ - const bNodeSocket &input_by_identifier(blender::StringRef identifier) const; - const bNodeSocket &output_by_identifier(blender::StringRef identifier) const; - bNodeSocket &input_by_identifier(blender::StringRef identifier); - bNodeSocket &output_by_identifier(blender::StringRef identifier); + const bNodeSocket *input_by_identifier(blender::StringRef identifier) const; + const bNodeSocket *output_by_identifier(blender::StringRef identifier) const; + bNodeSocket *input_by_identifier(blender::StringRef identifier); + bNodeSocket *output_by_identifier(blender::StringRef identifier); /** Lookup socket by its declaration. */ const bNodeSocket &socket_by_decl(const blender::nodes::SocketDeclaration &decl) const; bNodeSocket &socket_by_decl(const blender::nodes::SocketDeclaration &decl); diff --git a/source/blender/nodes/NOD_derived_node_tree.hh b/source/blender/nodes/NOD_derived_node_tree.hh index 89ac71a135e..b4dc4e505c9 100644 --- a/source/blender/nodes/NOD_derived_node_tree.hh +++ b/source/blender/nodes/NOD_derived_node_tree.hh @@ -328,12 +328,12 @@ inline DOutputSocket DNode::output(int index) const inline DInputSocket DNode::input_by_identifier(StringRef identifier) const { - return {context_, &bnode_->input_by_identifier(identifier)}; + return {context_, bnode_->input_by_identifier(identifier)}; } inline DOutputSocket DNode::output_by_identifier(StringRef identifier) const { - return {context_, &bnode_->output_by_identifier(identifier)}; + return {context_, bnode_->output_by_identifier(identifier)}; } /** \} */ diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index 8231461ff49..67907e313d1 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -123,7 +123,7 @@ class GeoNodeExecParams { } if constexpr (std::is_same_v) { BLI_assert(value.valid_for_socket( - eNodeSocketDatatype(node_.input_by_identifier(identifier).type))); + eNodeSocketDatatype(node_.input_by_identifier(identifier)->type))); } return value; } @@ -155,7 +155,7 @@ class GeoNodeExecParams { } if constexpr (std::is_same_v) { BLI_assert(value.valid_for_socket( - eNodeSocketDatatype(node_.input_by_identifier(identifier).type))); + eNodeSocketDatatype(node_.input_by_identifier(identifier)->type))); } return value; } @@ -186,7 +186,7 @@ class GeoNodeExecParams { this->check_output_access(identifier, type); if constexpr (std::is_same_v) { BLI_assert(value.valid_for_socket( - eNodeSocketDatatype(node_.output_by_identifier(identifier).type))); + eNodeSocketDatatype(node_.output_by_identifier(identifier)->type))); } #endif if constexpr (std::is_same_v) { @@ -278,7 +278,7 @@ class GeoNodeExecParams { { const int lf_index = lf_input_for_output_bsocket_usage_[node_.output_by_identifier(output_identifier) - .index_in_all_outputs()]; + ->index_in_all_outputs()]; return params_.get_input(lf_index); } @@ -292,7 +292,7 @@ class GeoNodeExecParams { if (!this->anonymous_attribute_output_is_required(output_identifier) && !force_create) { return std::nullopt; } - const bNodeSocket &output_socket = node_.output_by_identifier(output_identifier); + const bNodeSocket &output_socket = *node_.output_by_identifier(output_identifier); return get_output_attribute_id_(output_socket.index()); } @@ -301,9 +301,8 @@ class GeoNodeExecParams { */ NodeAttributeFilter get_attribute_filter(const StringRef output_identifier) const { - const int lf_index = - lf_input_for_attribute_propagation_to_output_[node_.output_by_identifier(output_identifier) - .index_in_all_outputs()]; + const int lf_index = lf_input_for_attribute_propagation_to_output_ + [node_.output_by_identifier(output_identifier)->index_in_all_outputs()]; const GeometryNodesReferenceSet &set = params_.get_input(lf_index); return NodeAttributeFilter(set); } diff --git a/source/blender/nodes/NOD_inverse_eval_params.hh b/source/blender/nodes/NOD_inverse_eval_params.hh index 6347c56daaa..a1a305db560 100644 --- a/source/blender/nodes/NOD_inverse_eval_params.hh +++ b/source/blender/nodes/NOD_inverse_eval_params.hh @@ -34,7 +34,7 @@ class InverseEvalParams { template T get_output(const StringRef identifier) const { - const bNodeSocket &socket = node.output_by_identifier(identifier); + const bNodeSocket &socket = *node.output_by_identifier(identifier); if (const bke::SocketValueVariant *value = socket_values_.lookup_ptr(&socket)) { return value->get(); } @@ -43,7 +43,7 @@ class InverseEvalParams { template T get_input(const StringRef identifier) const { - const bNodeSocket &socket = node.input_by_identifier(identifier); + const bNodeSocket &socket = *node.input_by_identifier(identifier); if (const bke::SocketValueVariant *value = socket_values_.lookup_ptr(&socket)) { return value->get(); } @@ -52,7 +52,7 @@ class InverseEvalParams { template void set_input(const StringRef identifier, T value) { - const bNodeSocket &socket = node.input_by_identifier(identifier); + const bNodeSocket &socket = *node.input_by_identifier(identifier); updated_socket_values_.add(&socket, bke::SocketValueVariant(value)); } }; diff --git a/source/blender/nodes/NOD_value_elem_eval.hh b/source/blender/nodes/NOD_value_elem_eval.hh index e29fb2919b2..655ea9494e5 100644 --- a/source/blender/nodes/NOD_value_elem_eval.hh +++ b/source/blender/nodes/NOD_value_elem_eval.hh @@ -28,7 +28,7 @@ class ElemEvalParams { template T get_input_elem(const StringRef identifier) const { - const bNodeSocket &socket = node.input_by_identifier(identifier); + const bNodeSocket &socket = *node.input_by_identifier(identifier); if (const ElemVariant *elem = this->elem_by_socket_.lookup_ptr(&socket)) { return std::get(elem->elem); } @@ -37,7 +37,7 @@ class ElemEvalParams { template void set_output_elem(const StringRef identifier, T elem) { - const bNodeSocket &socket = node.output_by_identifier(identifier); + const bNodeSocket &socket = *node.output_by_identifier(identifier); output_elems_.append({&socket, ElemVariant{elem}}); } }; @@ -60,7 +60,7 @@ class InverseElemEvalParams { template T get_output_elem(const StringRef identifier) const { - const bNodeSocket &socket = node.output_by_identifier(identifier); + const bNodeSocket &socket = *node.output_by_identifier(identifier); if (const ElemVariant *elem = this->elem_by_socket_.lookup_ptr(&socket)) { return std::get(elem->elem); } @@ -69,7 +69,7 @@ class InverseElemEvalParams { template void set_input_elem(const StringRef identifier, T elem) { - const bNodeSocket &socket = node.input_by_identifier(identifier); + const bNodeSocket &socket = *node.input_by_identifier(identifier); input_elems_.append({&socket, ElemVariant{elem}}); } }; diff --git a/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc b/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc index d5f11d4bc74..8e8be046c00 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc +++ b/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc @@ -227,10 +227,10 @@ static int node_gpu_material(GPUMaterial *material, material, node, "node_composite_color_balance_asc_cdl", inputs, outputs); } case CMP_NODE_COLOR_BALANCE_WHITEPOINT: { - const bNodeSocket &input_temperature = node->input_by_identifier("Input Temperature"); - const bNodeSocket &input_tint = node->input_by_identifier("Input Tint"); - const bNodeSocket &output_temperature = node->input_by_identifier("Output Temperature"); - const bNodeSocket &output_tint = node->input_by_identifier("Output Tint"); + const bNodeSocket &input_temperature = *node->input_by_identifier("Input Temperature"); + const bNodeSocket &input_tint = *node->input_by_identifier("Input Tint"); + const bNodeSocket &output_temperature = *node->input_by_identifier("Output Temperature"); + const bNodeSocket &output_tint = *node->input_by_identifier("Output Tint"); /* If all inputs are not linked, compute the white point matrix on the host and pass it to * the shader. */ diff --git a/source/blender/nodes/composite/nodes/node_composite_normal.cc b/source/blender/nodes/composite/nodes/node_composite_normal.cc index e92dae5b513..65c4b56ce59 100644 --- a/source/blender/nodes/composite/nodes/node_composite_normal.cc +++ b/source/blender/nodes/composite/nodes/node_composite_normal.cc @@ -38,7 +38,7 @@ using namespace blender::compositor; /* The vector value is stored in the default value of the output socket. */ static float3 get_normal(const bNode &node) { - const bNodeSocket &normal_output = node.output_by_identifier("Normal"); + const bNodeSocket &normal_output = *node.output_by_identifier("Normal"); const float3 node_normal = normal_output.default_value_typed()->value; return math::normalize(node_normal); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_bake.cc b/source/blender/nodes/geometry/nodes/node_geo_bake.cc index edf09441748..b023e3aa3fc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_bake.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_bake.cc @@ -582,7 +582,7 @@ static const bNodeSocket *node_internally_linked_input(const bNodeTree & /*tree* const bNodeSocket &output_socket) { /* Internal links should always map corresponding input and output sockets. */ - return &node.input_by_identifier(output_socket.identifier); + return node.input_by_identifier(output_socket.identifier); } static void node_blend_write(const bNodeTree & /*tree*/, const bNode &node, BlendWriter &writer) diff --git a/source/blender/nodes/intern/geometry_nodes_dependencies.cc b/source/blender/nodes/intern/geometry_nodes_dependencies.cc index 00996235a8c..1d5b22402d7 100644 --- a/source/blender/nodes/intern/geometry_nodes_dependencies.cc +++ b/source/blender/nodes/intern/geometry_nodes_dependencies.cc @@ -173,7 +173,7 @@ static bool needs_scene_render_params(const bNodeTree &ntree) if (node->is_muted()) { continue; } - const bNodeSocket &projection_matrix_socket = node->output_by_identifier("Projection Matrix"); + const bNodeSocket &projection_matrix_socket = *node->output_by_identifier("Projection Matrix"); if (projection_matrix_socket.is_logically_linked()) { return true; } diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc index ed69a90941a..ea809d72bfe 100644 --- a/source/blender/nodes/intern/node_geometry_exec.cc +++ b/source/blender/nodes/intern/node_geometry_exec.cc @@ -55,7 +55,7 @@ void GeoNodeExecParams::used_named_attribute(const StringRef attribute_name, void GeoNodeExecParams::check_input_geometry_set(StringRef identifier, const GeometrySet &geometry_set) const { - const SocketDeclaration &decl = *node_.input_by_identifier(identifier).runtime->declaration; + const SocketDeclaration &decl = *node_.input_by_identifier(identifier)->runtime->declaration; const decl::Geometry *geo_decl = dynamic_cast(&decl); if (geo_decl == nullptr) { return; diff --git a/source/blender/nodes/intern/socket_usage_inference.cc b/source/blender/nodes/intern/socket_usage_inference.cc index 377181b1697..551a6371087 100644 --- a/source/blender/nodes/intern/socket_usage_inference.cc +++ b/source/blender/nodes/intern/socket_usage_inference.cc @@ -419,7 +419,7 @@ struct SocketUsageInferencer { { const NodeInContext node = socket.owner_node(); this->usage_task__with_dependent_sockets( - socket, {&node->output_by_identifier(socket->identifier)}, {}, socket.context); + socket, {node->output_by_identifier(socket->identifier)}, {}, socket.context); } void usage_task__input__capture_attribute_node(const SocketInContext &socket) @@ -465,7 +465,7 @@ struct SocketUsageInferencer { } Vector dependent_sockets; if (StringRef(socket->identifier).startswith("Input_")) { - dependent_sockets.append(&node->output_by_identifier(socket->identifier)); + dependent_sockets.append(node->output_by_identifier(socket->identifier)); } else { /* The geometry and selection inputs are used whenever any of the zone outputs is used. */ @@ -1527,15 +1527,14 @@ InputSocketUsageParams::InputSocketUsageParams(SocketUsageInferencer &inferencer InferenceValue InputSocketUsageParams::get_input(const StringRef identifier) const { - const SocketInContext input_socket{compute_context_, - &this->node.input_by_identifier(identifier)}; + const SocketInContext input_socket{compute_context_, this->node.input_by_identifier(identifier)}; return inferencer_.get_socket_value(input_socket); } bool InputSocketUsageParams::menu_input_may_be(const StringRef identifier, const int enum_value) const { - BLI_assert(this->node.input_by_identifier(identifier).type == SOCK_MENU); + BLI_assert(this->node.input_by_identifier(identifier)->type == SOCK_MENU); const InferenceValue value = this->get_input(identifier); if (value.is_unknown()) { /* The value is unknown, so it may be the requested enum value. */ diff --git a/source/blender/nodes/shader/materialx/node_parser.cc b/source/blender/nodes/shader/materialx/node_parser.cc index 3f2a05009cc..eb9772d5a91 100644 --- a/source/blender/nodes/shader/materialx/node_parser.cc +++ b/source/blender/nodes/shader/materialx/node_parser.cc @@ -89,7 +89,7 @@ NodeItem NodeParser::create_output(const std::string &name, const NodeItem &item NodeItem NodeParser::get_input_default(const std::string &name, NodeItem::Type to_type) { - return get_default(node_->input_by_identifier(name), to_type); + return get_default(*node_->input_by_identifier(name), to_type); } NodeItem NodeParser::get_input_default(int index, NodeItem::Type to_type) @@ -99,7 +99,7 @@ NodeItem NodeParser::get_input_default(int index, NodeItem::Type to_type) NodeItem NodeParser::get_input_link(const std::string &name, NodeItem::Type to_type) { - return get_input_link(node_->input_by_identifier(name), to_type, false); + return get_input_link(*node_->input_by_identifier(name), to_type, false); } NodeItem NodeParser::get_input_link(int index, NodeItem::Type to_type) @@ -109,7 +109,7 @@ NodeItem NodeParser::get_input_link(int index, NodeItem::Type to_type) NodeItem NodeParser::get_input_value(const std::string &name, NodeItem::Type to_type) { - return get_input_value(node_->input_by_identifier(name), to_type); + return get_input_value(*node_->input_by_identifier(name), to_type); } NodeItem NodeParser::get_input_value(int index, NodeItem::Type to_type) @@ -119,7 +119,7 @@ NodeItem NodeParser::get_input_value(int index, NodeItem::Type to_type) NodeItem NodeParser::get_output_default(const std::string &name, NodeItem::Type to_type) { - return get_default(node_->output_by_identifier(name), to_type); + return get_default(*node_->output_by_identifier(name), to_type); } NodeItem NodeParser::get_output_default(int index, NodeItem::Type to_type)