Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/intern/COM_NodeOperation.cc
| Show All 35 Lines | |||||
| NodeOperation::NodeOperation() | NodeOperation::NodeOperation() | ||||
| { | { | ||||
| this->m_resolutionInputSocketIndex = 0; | this->m_resolutionInputSocketIndex = 0; | ||||
| this->m_width = 0; | this->m_width = 0; | ||||
| this->m_height = 0; | this->m_height = 0; | ||||
| this->m_btree = nullptr; | this->m_btree = nullptr; | ||||
| } | } | ||||
| /** | |||||
| * Generate a hash that identifies the operation result in the current execution. | |||||
| * Requires `hash_output_params` to be implemented, otherwise `std::nullopt` is returned. | |||||
| * If the operation parameters or its linked inputs change, the hash must be re-generated. | |||||
| */ | |||||
| std::optional<NodeOperationHash> NodeOperation::generate_hash() | |||||
| { | |||||
| params_hash_ = get_default_hash_2(m_width, m_height); | |||||
| /* Hash subclasses params. */ | |||||
| is_hash_output_params_implemented_ = true; | |||||
| hash_output_params(); | |||||
| if (!is_hash_output_params_implemented_) { | |||||
| return std::nullopt; | |||||
| } | |||||
| hash_param(getOutputSocket()->getDataType()); | |||||
| NodeOperationHash hash; | |||||
| hash.params_hash_ = params_hash_; | |||||
| hash.parents_hash_ = 0; | |||||
| for (NodeOperationInput &socket : m_inputs) { | |||||
| NodeOperation &input = socket.getLink()->getOperation(); | |||||
| const bool is_constant = input.get_flags().is_constant_operation; | |||||
| combine_hashes(hash.parents_hash_, get_default_hash(is_constant)); | |||||
| if (is_constant) { | |||||
| const float *elem = ((ConstantOperation *)&input)->get_constant_elem(); | |||||
| const int num_channels = COM_data_type_num_channels(socket.getDataType()); | |||||
| for (const int i : IndexRange(num_channels)) { | |||||
| combine_hashes(hash.parents_hash_, get_default_hash(elem[i])); | |||||
| } | |||||
| } | |||||
| else { | |||||
| combine_hashes(hash.parents_hash_, get_default_hash(input.get_id())); | |||||
| } | |||||
| } | |||||
| hash.type_hash_ = typeid(*this).hash_code(); | |||||
| hash.operation_ = this; | |||||
| return hash; | |||||
| } | |||||
| NodeOperationOutput *NodeOperation::getOutputSocket(unsigned int index) | NodeOperationOutput *NodeOperation::getOutputSocket(unsigned int index) | ||||
| { | { | ||||
| return &m_outputs[index]; | return &m_outputs[index]; | ||||
| } | } | ||||
| NodeOperationInput *NodeOperation::getInputSocket(unsigned int index) | NodeOperationInput *NodeOperation::getInputSocket(unsigned int index) | ||||
| { | { | ||||
| return &m_inputs[index]; | return &m_inputs[index]; | ||||
| ▲ Show 20 Lines • Show All 436 Lines • Show Last 20 Lines | |||||