Files
test2/source/blender/depsgraph/intern/node/deg_node_operation.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

285 lines
8.9 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2013 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup depsgraph
*/
#include "intern/node/deg_node_operation.hh"
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#include "intern/depsgraph.hh"
#include "intern/node/deg_node_component.hh"
#include "intern/node/deg_node_factory.hh"
#include "intern/node/deg_node_id.hh"
namespace blender::deg {
const char *operationCodeAsString(OperationCode opcode)
{
switch (opcode) {
/* Generic Operations. */
case OperationCode::OPERATION:
return "OPERATION";
case OperationCode::ID_PROPERTY:
return "ID_PROPERTY";
case OperationCode::PARAMETERS_ENTRY:
return "PARAMETERS_ENTRY";
case OperationCode::PARAMETERS_EVAL:
return "PARAMETERS_EVAL";
case OperationCode::PARAMETERS_EXIT:
return "PARAMETERS_EXIT";
case OperationCode::VISIBILITY:
return "VISIBILITY";
/* Hierarchy. */
case OperationCode::HIERARCHY:
return "HIERARCHY";
/* Animation, Drivers, etc. */
case OperationCode::ANIMATION_ENTRY:
return "ANIMATION_ENTRY";
case OperationCode::ANIMATION_EVAL:
return "ANIMATION_EVAL";
case OperationCode::ANIMATION_EXIT:
return "ANIMATION_EXIT";
case OperationCode::DRIVER:
return "DRIVER";
/* Scene related. */
case OperationCode::SCENE_EVAL:
return "SCENE_EVAL";
case OperationCode::AUDIO_ENTRY:
return "AUDIO_ENTRY";
case OperationCode::AUDIO_VOLUME:
return "AUDIO_VOLUME";
/* Object related. */
case OperationCode::OBJECT_FROM_LAYER_ENTRY:
return "OBJECT_FROM_LAYER_ENTRY";
case OperationCode::OBJECT_BASE_FLAGS:
return "OBJECT_BASE_FLAGS";
case OperationCode::OBJECT_FROM_LAYER_EXIT:
return "OBJECT_FROM_LAYER_EXIT";
case OperationCode::DIMENSIONS:
return "DIMENSIONS";
/* Transform. */
case OperationCode::TRANSFORM_INIT:
return "TRANSFORM_INIT";
case OperationCode::TRANSFORM_LOCAL:
return "TRANSFORM_LOCAL";
case OperationCode::TRANSFORM_PARENT:
return "TRANSFORM_PARENT";
case OperationCode::TRANSFORM_CONSTRAINTS:
return "TRANSFORM_CONSTRAINTS";
case OperationCode::TRANSFORM_FINAL:
return "TRANSFORM_FINAL";
case OperationCode::TRANSFORM_EVAL:
return "TRANSFORM_EVAL";
case OperationCode::TRANSFORM_SIMULATION_INIT:
return "TRANSFORM_SIMULATION_INIT";
/* Rigid body. */
case OperationCode::RIGIDBODY_REBUILD:
return "RIGIDBODY_REBUILD";
case OperationCode::RIGIDBODY_SIM:
return "RIGIDBODY_SIM";
case OperationCode::RIGIDBODY_TRANSFORM_COPY:
return "RIGIDBODY_TRANSFORM_COPY";
/* Geometry. */
case OperationCode::GEOMETRY_EVAL_INIT:
return "GEOMETRY_EVAL_INIT";
case OperationCode::MODIFIER:
return "MODIFIER";
case OperationCode::GEOMETRY_EVAL:
return "GEOMETRY_EVAL";
case OperationCode::GEOMETRY_EVAL_DONE:
return "GEOMETRY_EVAL_DONE";
case OperationCode::GEOMETRY_SHAPEKEY:
return "GEOMETRY_SHAPEKEY";
/* Object data. */
case OperationCode::LIGHT_PROBE_EVAL:
return "LIGHT_PROBE_EVAL";
case OperationCode::SPEAKER_EVAL:
return "SPEAKER_EVAL";
case OperationCode::SOUND_EVAL:
return "SOUND_EVAL";
case OperationCode::ARMATURE_EVAL:
return "ARMATURE_EVAL";
/* Pose. */
case OperationCode::POSE_INIT:
return "POSE_INIT";
case OperationCode::POSE_INIT_IK:
return "POSE_INIT_IK";
case OperationCode::POSE_CLEANUP:
return "POSE_CLEANUP";
case OperationCode::POSE_DONE:
return "POSE_DONE";
case OperationCode::POSE_IK_SOLVER:
return "POSE_IK_SOLVER";
case OperationCode::POSE_SPLINE_IK_SOLVER:
return "POSE_SPLINE_IK_SOLVER";
/* Bone. */
case OperationCode::BONE_LOCAL:
return "BONE_LOCAL";
case OperationCode::BONE_POSE_PARENT:
return "BONE_POSE_PARENT";
case OperationCode::BONE_CONSTRAINTS:
return "BONE_CONSTRAINTS";
case OperationCode::BONE_READY:
return "BONE_READY";
case OperationCode::BONE_DONE:
return "BONE_DONE";
case OperationCode::BONE_SEGMENTS:
return "BONE_SEGMENTS";
/* Particle System. */
case OperationCode::PARTICLE_SYSTEM_INIT:
return "PARTICLE_SYSTEM_INIT";
case OperationCode::PARTICLE_SYSTEM_EVAL:
return "PARTICLE_SYSTEM_EVAL";
case OperationCode::PARTICLE_SYSTEM_DONE:
return "PARTICLE_SYSTEM_DONE";
/* Particles Settings. */
case OperationCode::PARTICLE_SETTINGS_INIT:
return "PARTICLE_SETTINGS_INIT";
case OperationCode::PARTICLE_SETTINGS_EVAL:
return "PARTICLE_SETTINGS_EVAL";
case OperationCode::PARTICLE_SETTINGS_RESET:
return "PARTICLE_SETTINGS_RESET";
/* Point Cache. */
case OperationCode::POINT_CACHE_RESET:
return "POINT_CACHE_RESET";
/* File cache. */
case OperationCode::FILE_CACHE_UPDATE:
return "FILE_CACHE_UPDATE";
/* Batch cache. */
case OperationCode::GEOMETRY_SELECT_UPDATE:
return "GEOMETRY_SELECT_UPDATE";
/* Masks. */
case OperationCode::MASK_ANIMATION:
return "MASK_ANIMATION";
case OperationCode::MASK_EVAL:
return "MASK_EVAL";
/* Collections. */
case OperationCode::VIEW_LAYER_EVAL:
return "VIEW_LAYER_EVAL";
/* Copy on eval. */
case OperationCode::COPY_ON_EVAL:
return "COPY_ON_EVAL";
/* Shading. */
case OperationCode::SHADING:
return "SHADING";
case OperationCode::SHADING_DONE:
return "SHADING_DONE";
case OperationCode::MATERIAL_UPDATE:
return "MATERIAL_UPDATE";
case OperationCode::LIGHT_UPDATE:
return "LIGHT_UPDATE";
case OperationCode::WORLD_UPDATE:
return "WORLD_UPDATE";
/* Light linking. */
case OperationCode::LIGHT_LINKING_UPDATE:
return "LIGHT_LINKING_UPDATE";
Nodes: refactor node tree update handling Goals of this refactor: * More unified approach to updating everything that needs to be updated after a change in a node tree. * The updates should happen in the correct order and quadratic or worse algorithms should be avoided. * Improve detection of changes to the output to avoid tagging the depsgraph when it's not necessary. * Move towards a more declarative style of defining nodes by having a more centralized update procedure. The refactor consists of two main parts: * Node tree tagging and update refactor. * Generally, when changes are done to a node tree, it is tagged dirty until a global update function is called that updates everything in the correct order. * The tagging is more fine-grained compared to before, to allow for more precise depsgraph update tagging. * Depsgraph changes. * The shading specific depsgraph node for node trees as been removed. * Instead, there is a new `NTREE_OUTPUT` depsgrap node, which is only tagged when the output of the node tree changed (e.g. the Group Output or Material Output node). * The copy-on-write relation from node trees to the data block they are embedded in is now non-flushing. This avoids e.g. triggering a material update after the shader node tree changed in unrelated ways. Instead the material has a flushing relation to the new `NTREE_OUTPUT` node now. * The depsgraph no longer reports data block changes through to cycles through `Depsgraph.updates` when only the node tree changed in ways that do not affect the output. Avoiding unnecessary updates seems to work well for geometry nodes and cycles. The situation is a bit worse when there are drivers on the node tree, but that could potentially be improved separately in the future. Avoiding updates in eevee and the compositor is more tricky, but also less urgent. * Eevee updates are triggered by calling `DRW_notify_view_update` in `ED_render_view3d_update` indirectly from `DEG_editors_update`. * Compositor updates are triggered by `ED_node_composite_job` in `node_area_refresh`. This is triggered by calling `ED_area_tag_refresh` in `node_area_listener`. Removing updates always has the risk of breaking some dependency that no one was aware of. It's not unlikely that this will happen here as well. Adding back missing updates should be quite a bit easier than getting rid of unnecessary updates though. Differential Revision: https://developer.blender.org/D13246
2021-12-21 15:18:56 +01:00
/* Node Tree. */
case OperationCode::NTREE_OUTPUT:
return "NTREE_OUTPUT";
case OperationCode::NTREE_GEOMETRY_PREPROCESS:
return "NTREE_GEOMETRY_PREPROCESS";
/* Movie clip. */
case OperationCode::MOVIECLIP_EVAL:
return "MOVIECLIP_EVAL";
/* Image. */
case OperationCode::IMAGE_ANIMATION:
return "IMAGE_ANIMATION";
/* Synchronization. */
case OperationCode::SYNCHRONIZE_TO_ORIGINAL:
return "SYNCHRONIZE_TO_ORIGINAL";
/* Generic datablock. */
case OperationCode::GENERIC_DATABLOCK_UPDATE:
return "GENERIC_DATABLOCK_UPDATE";
/* Sequencer. */
case OperationCode::SEQUENCES_EVAL:
return "SEQUENCES_EVAL";
/* instancing. */
case OperationCode::INSTANCER:
return "INSTANCER";
case OperationCode::INSTANCE:
return "INSTANCE";
case OperationCode::INSTANCE_GEOMETRY:
return "INSTANCE_GEOMETRY";
}
BLI_assert_msg(0, "Unhandled operation code, should never happen.");
return "UNKNOWN";
}
OperationNode::OperationNode() : name_tag(-1), flag(0) {}
string OperationNode::identifier() const
{
return string(operationCodeAsString(opcode)) + "(" + name + ")";
}
string OperationNode::full_identifier() const
{
string owner_str = owner->owner->name;
if (owner->type == NodeType::BONE || !owner->name.empty()) {
owner_str += "/" + owner->name;
}
return owner_str + "/" + identifier();
}
void OperationNode::tag_update(Depsgraph *graph, eUpdateSource source)
{
/* Ensure that there is an entry tag for this update.
*
* Note that the node might already be tagged for an update due invisible state of the node
* during previous dependency evaluation. Here the node gets re-tagged, so we need to give
* the evaluated clues that evaluation needs to happen again. */
graph->add_entry_tag(this);
2022-08-11 09:44:33 +10:00
/* Enforce dynamic visibility code-path update.
* This ensures visibility flags are consistently propagated throughout the dependency graph when
* there is no animated visibility in the graph.
*
* For example this ensures that graph is updated properly when manually toggling non-animated
* modifier visibility. */
if (opcode == OperationCode::VISIBILITY) {
graph->need_update_nodes_visibility = true;
}
/* Tag for update, but also note that this was the source of an update. */
flag |= (DEPSOP_FLAG_NEEDS_UPDATE | DEPSOP_FLAG_DIRECTLY_MODIFIED);
switch (source) {
case DEG_UPDATE_SOURCE_TIME:
case DEG_UPDATE_SOURCE_RELATIONS:
case DEG_UPDATE_SOURCE_VISIBILITY:
Geometry Nodes: new Bake node This adds a new `Bake` node which allows saving and loading intermediate geometries. Typical use cases we want address with this currently are: * Bake some data for use with a render engine. * Bake parts of the node tree explicitly for better performance. For now, the format that is written to disk is not considered to be an import/export format. It's not guaranteed that data written with one Blender version can be read by another Blender version. For that it's better to use proper interchange formats. Better support for those will be added eventually as well. We also plan an `Import Bake` node that allows reading the blender-specific baked data independent of the Bake node and at different frames. The baking works very similar to the baking in the simulation zone (UI and implementation wise). Major differences are: * The Bake node has a `Bake Still` and `Bake Animation` mode. * The Bake node doesn't do automatic caching. Implementation details: * Refactored how we create the Python operators for moving socket items so that it also makes sense for non-zones. * The `ModifierCache` stores an independent map of `SimulationNodeCache` and `BakeNodeCache`, but both share a common data structure for the actually baked data. * For baking, the `Bake` node is added as a side-effect-node in the modifier. This will make sure that the node is baked even if it's currently not connected to the output. * Had to add a new `DEG_id_tag_update_for_side_effect_request` function that is used during baking. It's necessary because I want to evaluate the object again even though none of its inputs changed. The reevaluation is necessary to create the baked data. Using `DEG_id_tag_update` technically works as well, but has the problem that it also uses the `DEG_UPDATE_SOURCE_USER_EDIT` flag which (rightly) invalidates simulation caches which shouldn't happen here. * Slightly refactored the timeline drawing so that it can also show the baked ranges of Bake nodes. It does not show anything for baked nodes with a in Still mode though. * The bake operator is refactored to bake a list of `NodeBakeRequest` which makes the code easier to follow compared to the previous nested `ObjectBakeData > ModifierBakeData > NodeBakeData` data structure. * The bake operators are disabled when the .blend file is not yet saved. This is technically only necessary when the bake path depends on the .blend file path but seems ok to force the user anyway (otherwise the bake path may be lost as well if it's set explicitly). * The same operators are used to bake and delete single bakes in `Bake` nodes and `Simulation Zones`. On top of that, there are separate operators of baking and deleting all simulation bakes (those ignore bake nodes). * The `Bake` node remembers which inputs have been fields and thus may be baked as attributes. For that it uses an `Is Attribute` flag on the socket item. This is needed because the baked data may still contain attribute data, even if the inputs to the bake node are disconnected. * Similar to simulation zones, the behavior of `Bake` nodes is passed into the geometry nodes evaluation from the outside (from the modifier only currently). This is done by providing the new `GeoNodesBakeParams` in `GeoNodesCallData` when executing geometry nodes. Next Steps (mostly because they also involve simulations): * Visualize nodes that have not been evaluated in the last evaluation. * Fix issue with seemingly loosing baked data after undo. * Improve error handling when baked data is not found. * Show bake node in link drag search. * Higher level tools for managing bakes. Pull Request: https://projects.blender.org/blender/blender/pulls/115466
2023-12-18 13:01:06 +01:00
case DEG_UPDATE_SOURCE_SIDE_EFFECT_REQUEST:
/* Currently nothing. */
break;
case DEG_UPDATE_SOURCE_USER_EDIT:
flag |= DEPSOP_FLAG_USER_MODIFIED;
break;
}
}
void OperationNode::set_as_entry()
{
BLI_assert(owner != nullptr);
owner->set_entry_operation(this);
}
void OperationNode::set_as_exit()
{
BLI_assert(owner != nullptr);
owner->set_exit_operation(this);
}
DEG_DEPSNODE_DEFINE(OperationNode, NodeType::OPERATION, "Operation");
static DepsNodeFactoryImpl<OperationNode> DNTI_OPERATION;
void deg_register_operation_depsnodes()
{
register_node_typeinfo(&DNTI_OPERATION);
}
} // namespace blender::deg