|
Blender V5.0
|
#include <algorithm>#include <variant>#include "MEM_guardedalloc.h"#include "CLG_log.h"#include "DNA_key_types.h"#include "DNA_layer_types.h"#include "DNA_mesh_types.h"#include "DNA_meshdata_types.h"#include "DNA_object_types.h"#include "DNA_scene_types.h"#include "BLI_array_utils.h"#include "BLI_implicit_sharing.hh"#include "BLI_listbase.h"#include "BLI_math_base.h"#include "BLI_string.h"#include "BLI_task.hh"#include "BLI_vector.hh"#include "BKE_context.hh"#include "BKE_customdata.hh"#include "BKE_deform.hh"#include "BKE_editmesh.hh"#include "BKE_key.hh"#include "BKE_layer.hh"#include "BKE_lib_id.hh"#include "BKE_main.hh"#include "BKE_mesh.hh"#include "BKE_object.hh"#include "BKE_undo_system.hh"#include "DEG_depsgraph.hh"#include "ED_mesh.hh"#include "ED_object.hh"#include "ED_undo.hh"#include "ED_util.hh"#include "WM_api.hh"#include "WM_types.hh"#include "BLI_array_store.h"#include "BLI_array_store_utils.h"#include "BLI_task.h"Go to the source code of this file.
Classes | |
| struct | BArrayCustomData |
| struct | UndoMesh |
| struct | UMArrayData |
| struct | MeshUndoStep_Elem |
| struct | MeshUndoStep_SceneData |
| struct | MeshUndoStep |
Macros | |
| #define | USE_ARRAY_STORE |
| #define | ARRAY_CHUNK_SIZE_IN_BYTES 65536 |
| #define | ARRAY_CHUNK_NUM_MIN 256 |
| #define | USE_ARRAY_STORE_THREAD |
| #define | USE_ARRAY_STORE_RLE |
Functions | |
| static void * | undomesh_from_editmesh (UndoMesh *um, BMEditMesh *em, Key *key, const ListBase *vertex_group_names, const int vertex_group_active_index, UndoMesh *um_ref) |
| static void | undomesh_to_editmesh (UndoMesh *um, BMEditMesh *em, ListBase *vertex_group_names, int *vertex_group_active_index) |
| static void | undomesh_free_data (UndoMesh *um) |
| static Object * | editmesh_object_from_context (bContext *C) |
Undo Conversion | |
| static size_t | array_chunk_size_calc (const size_t stride) |
| static bool | um_customdata_layer_use_rle (const BArrayCustomData *bcd) |
Array Store Utilities | |
| static UndoMesh ** | mesh_undostep_reference_elems_from_objects (Object **object, int object_len) |
Implements ED Undo System | |
| |
| static bool | mesh_undosys_poll (bContext *C) |
| static bool | mesh_undosys_step_encode (bContext *C, Main *bmain, UndoStep *us_p) |
| static void | mesh_undosys_step_decode (bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir, bool) |
| static void | mesh_undosys_step_free (UndoStep *us_p) |
| static void | mesh_undosys_foreach_ID_ref (UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) |
| void | ED_mesh_undosys_type (UndoType *ut) |
Variables | |
| static CLG_LogRef | LOG = {"undo.mesh"} |
| #define ARRAY_CHUNK_NUM_MIN 256 |
Definition at line 72 of file editmesh_undo.cc.
Referenced by array_chunk_size_calc().
| #define ARRAY_CHUNK_SIZE_IN_BYTES 65536 |
This used to be much smaller (256), but this caused too much overhead when selection moved to boolean arrays. Especially with high-poly meshes where managing a large number of small chunks could be slow, blocking user interactivity. Use a larger value (in bytes) which calculates the chunk size using array_chunk_size_calc. See: #105046 & #105205.
Definition at line 71 of file editmesh_undo.cc.
Referenced by array_chunk_size_calc().
| #define ARRAY_STORE_INDEX_NUM (ARRAY_STORE_INDEX_MSEL + 1) |
Definition at line 199 of file editmesh_undo.cc.
Referenced by um_arraystore_compact_with_info(), and um_arraystore_free().
| #define USE_ARRAY_STORE |
Definition at line 53 of file editmesh_undo.cc.
| #define USE_ARRAY_STORE_RLE |
Use run length encoding for boolean custom-data.
Avoid poor performance caused by boolean arrays not having enough uniqueness to efficiently de-duplicate, see: #136737.
NOTE(@ideasman42): This has the down-side that creating undo steps needs to encode data before comparing it with the previous state (when creating each undo step). Adding additional work even when nothing change.
Since there is overhead for RLE encoding this is only used on boolean array, typically used for storing selection/hidden state as well as edge flags. The encoding has also been optimized for performance instead of "compression" which would pack bits into the smallest possible space.
In practice, arrays of 32 million booleans (on an AMD TRX 3990X):
There is also the benefit of reduced memory use, although that isn't the goal.
Definition at line 98 of file editmesh_undo.cc.
| #define USE_ARRAY_STORE_THREAD |
Definition at line 74 of file editmesh_undo.cc.
| anonymous enum |
Store separate BArrayStore_AtSize so multiple threads can access array stores without locking.
| Enumerator | |
|---|---|
| ARRAY_STORE_INDEX_VERT | |
| ARRAY_STORE_INDEX_EDGE | |
| ARRAY_STORE_INDEX_LOOP | |
| ARRAY_STORE_INDEX_POLY | |
| ARRAY_STORE_INDEX_POLY_OFFSETS | |
| ARRAY_STORE_INDEX_SHAPE | |
| ARRAY_STORE_INDEX_MSEL | |
Definition at line 190 of file editmesh_undo.cc.
|
static |
Definition at line 114 of file editmesh_undo.cc.
References ARRAY_CHUNK_NUM_MIN, ARRAY_CHUNK_SIZE_IN_BYTES, and power_of_2_max_i().
Referenced by um_arraystore_cd_compact().
| void ED_mesh_undosys_type | ( | UndoType * | ut | ) |
Export for ED_undo_sys.
Definition at line 1220 of file editmesh_undo.cc.
References UndoType::flags, mesh_undosys_foreach_ID_ref(), mesh_undosys_poll(), mesh_undosys_step_decode(), mesh_undosys_step_encode(), mesh_undosys_step_free(), UndoType::name, UndoType::poll, UndoType::step_decode, UndoType::step_encode, UndoType::step_foreach_ID_ref, UndoType::step_free, UndoType::step_size, and UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE.
Referenced by ED_undosys_type_init().
Definition at line 1015 of file editmesh_undo.cc.
References BKE_view_layer_edit_object_get(), BKE_view_layer_synced_ensure(), C, CTX_data_scene(), CTX_data_view_layer(), Object::data, OB_MESH, Mesh::runtime, and Object::type.
Referenced by mesh_undosys_poll().
Create an array of UndoMesh from objects.
where each element in the resulting array is the most recently created undo-mesh for the object's mesh. When no undo-mesh can be found that array index is nullptr.
This is used for de-duplicating memory between undo steps, failure to find the undo step will store a full duplicate in memory. define DEBUG_PRINT to check memory is de-duplicating as expected.
Definition at line 780 of file editmesh_undo.cc.
References BLI_assert, BLI_ghash_free(), BLI_ghash_insert(), BLI_ghash_len(), BLI_ghash_popkey(), BLI_ghash_ptr_new_ex(), i, Mesh::id, UndoMesh::local_prev, MEM_calloc_arrayN(), MEM_freeN(), UndoMesh::mesh, POINTER_FROM_INT, ID::session_uid, and um_arraystore.
Referenced by mesh_undosys_step_encode().
|
static |
Definition at line 1207 of file editmesh_undo.cc.
References MeshUndoStep::elems, MeshUndoStep::elems_len, i, MeshUndoStep_Elem::obedit_ref, and MeshUndoStep::scene_ref.
Referenced by ED_mesh_undosys_type().
|
static |
Definition at line 1064 of file editmesh_undo.cc.
References C, and editmesh_object_from_context().
Referenced by ED_mesh_undosys_type(), and mesh_undosys_step_decode().
|
static |
Definition at line 1130 of file editmesh_undo.cc.
References BKE_object_is_in_editmode(), BLI_assert, BMEditMesh::bm, C, CLOG_ERROR, CTX_data_scene(), CTX_data_view_layer(), CTX_wm_manager(), MeshUndoStep_Elem::data, Object::data, DEG_id_tag_update(), ED_undo_object_editmode_restore_helper(), ED_undo_object_editmode_validate_scene_from_windows(), ED_undo_object_set_active_or_warn(), MeshUndoStep::elems, MeshUndoStep::elems_len, i, Mesh::id, Object::id, ID_RECALC_GEOMETRY, Main::is_memfile_undo_flush_needed, LOG, mesh_undosys_poll(), ID::name, UndoStep::name, NC_GEOM, ND_DATA, BMEditMesh::needs_flush_to_id, MeshUndoStep_Elem::obedit_ref, Mesh::runtime, MeshUndoStep::scene_data, MeshUndoStep::scene_ref, MeshUndoStep_SceneData::selectmode, ToolSettings::selectmode, BMesh::shapenr, Object::shapenr, Scene::toolsettings, undomesh_to_editmesh(), MeshUndoStep_SceneData::uv_flag, ToolSettings::uv_flag, UV_FLAG_SELECT_ISLAND, UV_FLAG_SELECT_SYNC, MeshUndoStep_SceneData::uv_selectmode, ToolSettings::uv_selectmode, MeshUndoStep_SceneData::uv_sticky, ToolSettings::uv_sticky, Mesh::vertex_group_active_index, Mesh::vertex_group_names, and WM_event_add_notifier().
Referenced by ED_mesh_undosys_type().
As this is only data storage it is safe to set the session ID here.
Definition at line 1069 of file editmesh_undo.cc.
References C, CTX_data_scene(), CTX_data_view_layer(), blender::Vector< T, InlineBufferCapacity, Allocator >::data(), MeshUndoStep_Elem::data, UndoStep::data_size, ED_undo_editmode_objects_from_view_layer(), MeshUndoStep::elems, MeshUndoStep::elems_len, i, Mesh::id, Main::is_memfile_undo_flush_needed, Mesh::key, MEM_calloc_arrayN(), MEM_freeN(), UndoMesh::mesh, mesh_undostep_reference_elems_from_objects(), BMEditMesh::needs_flush_to_id, MeshUndoStep_Elem::obedit_ref, Mesh::runtime, MeshUndoStep::scene_data, MeshUndoStep::scene_ref, MeshUndoStep_SceneData::selectmode, ToolSettings::selectmode, ID::session_uid, blender::Vector< T, InlineBufferCapacity, Allocator >::size(), MeshUndoStep::step, Scene::toolsettings, UndoMesh::undo_size, undomesh_from_editmesh(), MeshUndoStep_SceneData::uv_flag, ToolSettings::uv_flag, MeshUndoStep_SceneData::uv_selectmode, ToolSettings::uv_selectmode, MeshUndoStep_SceneData::uv_sticky, ToolSettings::uv_sticky, Mesh::vertex_group_active_index, and Mesh::vertex_group_names.
Referenced by ED_mesh_undosys_type().
|
static |
Definition at line 1196 of file editmesh_undo.cc.
References MeshUndoStep_Elem::data, MeshUndoStep::elems, MeshUndoStep::elems_len, i, MEM_freeN(), and undomesh_free_data().
Referenced by ED_mesh_undosys_type().
|
static |
Definition at line 217 of file editmesh_undo.cc.
References ImplicitSharingInfo::add_user(), array_chunk_size_calc(), BLI_array_store_at_size_ensure(), BLI_array_store_rle_encode(), BLI_array_store_state_add(), CustomData_layertype_is_dynamic(), CustomData_sizeof(), CustomDataLayer::data, i, CustomData::layers, MEM_freeN(), BArrayCustomData::next, Array< T, InlineBufferCapacity, Allocator >::reinitialize(), CustomDataLayer::sharing_info, BArrayCustomData::states, CustomData::totlayer, BArrayCustomData::type, CustomDataLayer::type, um_arraystore, and um_customdata_layer_use_rle().
|
static |
Definition at line 375 of file editmesh_undo.cc.
References BLI_array_store_rle_decode(), BLI_array_store_state_data_get_alloc(), BLI_assert, CustomData_sizeof(), CustomDataLayer::data, data, i, blender::implicit_sharing::info_for_mem_free(), CustomData::layers, MEM_freeN(), MEM_malloc_arrayN(), BArrayCustomData::next, CustomDataLayer::sharing_info, Array< T, InlineBufferCapacity, Allocator >::size(), state, BArrayCustomData::states, BArrayCustomData::type, CustomDataLayer::type, um_customdata_layer_use_rle(), and UNUSED_VARS_NDEBUG.
Referenced by um_arraystore_expand().
|
static |
Definition at line 432 of file editmesh_undo.cc.
References BLI_array_store_at_size_get(), BLI_array_store_state_remove(), CustomData_sizeof(), i, BArrayCustomData::next, Array< T, InlineBufferCapacity, Allocator >::size(), state, BArrayCustomData::states, BArrayCustomData::type, and um_arraystore.
Referenced by um_arraystore_free().
Move data from allocated arrays to de-duplicated states and clear arrays.
Definition at line 584 of file editmesh_undo.cc.
References um_arraystore_compact_ex().
Referenced by um_arraystore_compact_with_info().
|
static |
Definition at line 648 of file editmesh_undo.cc.
References UMArrayData::um, um_arraystore_compact_with_info(), and UMArrayData::um_ref.
Referenced by undomesh_from_editmesh().
| create | When false, only free the arrays. This is done since when reading from an undo state, they must be temporarily expanded. then discarded afterwards, having this argument avoids having 2x code paths. |
Definition at line 460 of file editmesh_undo.cc.
References Mesh::corners_num, Mesh::edges_num, Mesh::faces_num, UndoMesh::mesh, blender::threading::parallel_invoke(), and Mesh::verts_num.
Referenced by um_arraystore_compact(), and um_arraystore_expand_clear().
Definition at line 589 of file editmesh_undo.cc.
References ARRAY_STORE_INDEX_NUM, BLI_array_store_at_size_calc_memory_usage(), printf, TIMEIT_END, TIMEIT_START, um_arraystore, and um_arraystore_compact().
Referenced by um_arraystore_compact_cb(), and undomesh_from_editmesh().
|
static |
Definition at line 664 of file editmesh_undo.cc.
References BLI_array_store_state_data_get_alloc(), BLI_assert, Key::block, Mesh::corner_data, Mesh::corners_num, KeyBlock::data, UndoMesh::edata, Mesh::edge_data, Mesh::edges_num, Key::elemsize, Mesh::face_data, Mesh::face_offset_indices, UndoMesh::face_offset_indices, Mesh::faces_num, ListBase::first, i, blender::implicit_sharing::info_for_mem_free(), Mesh::key, UndoMesh::keyblocks, UndoMesh::ldata, UndoMesh::mesh, Mesh::mselect, UndoMesh::mselect, KeyBlock::next, UndoMesh::pdata, Mesh::runtime, state, UndoMesh::store, KeyBlock::totelem, Key::totkey, Mesh::totselect, um_arraystore_cd_expand(), UNUSED_VARS_NDEBUG, UndoMesh::vdata, Mesh::vert_data, and Mesh::verts_num.
Referenced by undomesh_free_data(), and undomesh_to_editmesh().
|
static |
Remove data we only expanded for temporary use.
Definition at line 659 of file editmesh_undo.cc.
References um_arraystore_compact_ex().
Referenced by undomesh_to_editmesh().
|
static |
Definition at line 707 of file editmesh_undo.cc.
References ARRAY_STORE_INDEX_EDGE, ARRAY_STORE_INDEX_LOOP, ARRAY_STORE_INDEX_MSEL, ARRAY_STORE_INDEX_NUM, ARRAY_STORE_INDEX_POLY, ARRAY_STORE_INDEX_POLY_OFFSETS, ARRAY_STORE_INDEX_SHAPE, ARRAY_STORE_INDEX_VERT, BLI_array_store_at_size_clear(), BLI_array_store_at_size_get(), BLI_array_store_state_remove(), BLI_assert, BLI_task_pool_free(), UndoMesh::edata, Key::elemsize, Mesh::face_offset_indices, UndoMesh::face_offset_indices, i, Mesh::key, UndoMesh::keyblocks, UndoMesh::ldata, MEM_freeN(), UndoMesh::mesh, Mesh::mselect, UndoMesh::mselect, UndoMesh::pdata, printf, state, UndoMesh::store, Key::totkey, um_arraystore, um_arraystore_cd_free(), and UndoMesh::vdata.
Referenced by undomesh_free_data().
|
static |
Definition at line 130 of file editmesh_undo.cc.
References BLI_assert, CD_PROP_BOOL, CustomData_sizeof(), and BArrayCustomData::type.
Referenced by um_arraystore_cd_compact(), and um_arraystore_cd_expand().
|
static |
Definition at line 986 of file editmesh_undo.cc.
References BKE_id_free(), BLI_assert, BLI_findindex(), BLI_remlink(), BLI_task_pool_work_and_wait(), Mesh::key, UndoMesh::mesh, um_arraystore, um_arraystore_expand(), and um_arraystore_free().
Referenced by mesh_undosys_step_free().
|
static |
Copy data from em into um.
| um_ref | The reference to use for de-duplicating memory between undo-steps. |
Definition at line 828 of file editmesh_undo.cc.
References BKE_defgroup_copy_list(), BKE_id_copy_ex(), BLI_addtail(), BLI_array_is_zeroed, BLI_assert, BLI_task_pool_create_background(), BLI_task_pool_push(), BLI_task_pool_work_and_wait(), BMEditMesh::bm, BM_mesh_bm_to_me(), BM_mesh_is_valid(), BM_mesh_uvselect_is_valid(), CD_MASK_SHAPE_KEYINDEX, CD_PROP_FLOAT2, CustomData_get_offset(), Key::id, Mesh::key, BMesh::ldata, LIB_ID_COPY_LOCALIZE, LIB_ID_COPY_NO_ANIMDATA, MEM_mallocN(), UndoMesh::mesh, blender::bke::mesh_new_no_attributes(), params, BMEditMesh::selectmode, UndoMesh::selectmode, BMesh::shapenr, UndoMesh::shapenr, TASK_PRIORITY_LOW, UMArrayData::um, um_arraystore, um_arraystore_compact_cb(), um_arraystore_compact_with_info(), UMArrayData::um_ref, UNUSED_VARS, BMesh::uv_select_sync_valid, Mesh::vertex_group_active_index, Mesh::vertex_group_names, and CustomData_MeshMasks::vmask.
Referenced by mesh_undosys_step_encode().
|
static |
Copy data from um into em.
Definition at line 923 of file editmesh_undo.cc.
References BMeshFromMeshParams::active_shapekey, BKE_defgroup_copy_list(), BKE_editmesh_create(), BKE_editmesh_looptris_and_normals_calc(), BLI_freelistN(), BLI_task_pool_work_and_wait(), bm, BMEditMesh::bm, BM_mesh_bm_from_me(), BM_mesh_create(), BM_SPACEARR_DIRTY_ALL, BMALLOC_TEMPLATE_FROM_ME, BMeshFromMeshParams::calc_face_normal, BMeshFromMeshParams::calc_vert_normal, EDBM_mesh_free_data(), UndoMesh::mesh, BMEditMesh::selectmode, UndoMesh::selectmode, BMesh::shapenr, UndoMesh::shapenr, TIMEIT_END, TIMEIT_START, um_arraystore, um_arraystore_expand(), um_arraystore_expand_clear(), BMeshCreateParams::use_toolflags, Mesh::vertex_group_active_index, and Mesh::vertex_group_names.
Referenced by mesh_undosys_step_decode().
| BArrayStore_AtSize bs_stride[ARRAY_STORE_INDEX_NUM] |
Definition at line 202 of file editmesh_undo.cc.
| ListBase local_links |
A list of UndoMesh items ordered from oldest to newest used to access previous undo data for a mesh.
Definition at line 209 of file editmesh_undo.cc.
|
static |
We only need this locally.
Definition at line 106 of file editmesh_undo.cc.
| TaskPool* task_pool |
Definition at line 212 of file editmesh_undo.cc.
Referenced by BKE_lib_override_library_main_operations_create(), BLI_task_parallel_mempool(), bvh_reference_sort(), bvh_reference_sort_threaded(), blender::deg::deg_evaluate_on_refresh(), SVMShaderManager::device_update_specific(), distribute_particles_on_dm(), do_sequence_proxy(), blender::fn::lazy_function::Executor::execute(), blender::ed::vse::execute_read_sound_waveform_task(), blender::ed::vse::free_read_sound_waveform_task(), blender::ed::vse::preview_startjob(), project_paint_op(), psys_cache_child_paths(), start_prefetch_threads(), and blender::fn::lazy_function::Executor::~Executor().
| struct { ... } um_arraystore |
| int users |
Definition at line 203 of file editmesh_undo.cc.