Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_runtime.c
| Show All 39 Lines | |||||
| #include "BKE_shrinkwrap.h" | #include "BKE_shrinkwrap.h" | ||||
| #include "BKE_subdiv_ccg.h" | #include "BKE_subdiv_ccg.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mesh Runtime Struct Utils | /** \name Mesh Runtime Struct Utils | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Default values defined at read time. | * \brief Initialize the runtime mutexes of the given mesh. | ||||
| * | |||||
| * Any existing mutexes will be overridden. | |||||
| */ | */ | ||||
| void BKE_mesh_runtime_reset(Mesh *mesh) | static void BKE_mesh_runtime_init_mutexes(Mesh *mesh) | ||||
mont29: static functions do not take the module prefix (so just `mesh_runtime_init_mutexes`) | |||||
| { | { | ||||
| memset(&mesh->runtime, 0, sizeof(mesh->runtime)); | |||||
| mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | ||||
| BLI_mutex_init(mesh->runtime.eval_mutex); | BLI_mutex_init(mesh->runtime.eval_mutex); | ||||
| mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex"); | mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex"); | ||||
| BLI_mutex_init(mesh->runtime.render_mutex); | BLI_mutex_init(mesh->runtime.render_mutex); | ||||
| } | } | ||||
| /** | |||||
| * \brief free the mutexes of the given mesh runtime. | |||||
| */ | |||||
| static void BKE_mesh_runtime_free_mutexes(Mesh *mesh) | |||||
Done Inline Actionsstatic functions do not take the module prefix (so just mesh_runtime_free_mutexes) mont29: static functions do not take the module prefix (so just `mesh_runtime_free_mutexes`) | |||||
| { | |||||
| if (mesh->runtime.eval_mutex != NULL) { | |||||
| BLI_mutex_end(mesh->runtime.eval_mutex); | |||||
| MEM_freeN(mesh->runtime.eval_mutex); | |||||
| mesh->runtime.eval_mutex = NULL; | |||||
| } | |||||
| if (mesh->runtime.render_mutex != NULL) { | |||||
| BLI_mutex_end(mesh->runtime.render_mutex); | |||||
| MEM_freeN(mesh->runtime.render_mutex); | |||||
| mesh->runtime.render_mutex = NULL; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * \brief Initialize the runtime of the given mesh. | |||||
| * | |||||
| * Function expects that the runtime is already cleared. | |||||
| */ | |||||
| void BKE_mesh_runtime_init_data(Mesh *mesh) | |||||
| { | |||||
| BKE_mesh_runtime_init_mutexes(mesh); | |||||
| } | |||||
| /** | |||||
| * \brief Free all data (and mutexes) inside the runtime of the given mesh. | |||||
| */ | |||||
| void BKE_mesh_runtime_free_data(Mesh *mesh) | |||||
| { | |||||
| BKE_mesh_runtime_clear_cache(mesh); | |||||
| BKE_mesh_runtime_free_mutexes(mesh); | |||||
| } | |||||
| /* Clear all pointers which we don't want to be shared on copying the datablock. | /* Clear all pointers which we don't want to be shared on copying the datablock. | ||||
| * However, keep all the flags which defines what the mesh is (for example, that | * However, keep all the flags which defines what the mesh is (for example, that | ||||
| * it's deformed only, or that its custom data layers are out of date.) */ | * it's deformed only, or that its custom data layers are out of date.) */ | ||||
| void BKE_mesh_runtime_reset_on_copy(Mesh *mesh, const int UNUSED(flag)) | void BKE_mesh_runtime_reset_on_copy(Mesh *mesh, const int UNUSED(flag)) | ||||
| { | { | ||||
| Mesh_Runtime *runtime = &mesh->runtime; | Mesh_Runtime *runtime = &mesh->runtime; | ||||
| runtime->mesh_eval = NULL; | runtime->mesh_eval = NULL; | ||||
| runtime->edit_data = NULL; | runtime->edit_data = NULL; | ||||
| runtime->batch_cache = NULL; | runtime->batch_cache = NULL; | ||||
| runtime->subdiv_ccg = NULL; | runtime->subdiv_ccg = NULL; | ||||
| memset(&runtime->looptris, 0, sizeof(runtime->looptris)); | memset(&runtime->looptris, 0, sizeof(runtime->looptris)); | ||||
| runtime->bvh_cache = NULL; | runtime->bvh_cache = NULL; | ||||
| runtime->shrinkwrap_data = NULL; | runtime->shrinkwrap_data = NULL; | ||||
| mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | BKE_mesh_runtime_init_mutexes(mesh); | ||||
Done Inline ActionsThis has nothing to do here? You create a set of functions dedicated to mutexes, but then wipe out the entire runtime struct in them? mont29: This has nothing to do here? You create a set of functions dedicated to mutexes, but then wipe… | |||||
| BLI_mutex_init(mesh->runtime.eval_mutex); | |||||
| mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex"); | |||||
| BLI_mutex_init(mesh->runtime.render_mutex); | |||||
| } | } | ||||
| void BKE_mesh_runtime_clear_cache(Mesh *mesh) | void BKE_mesh_runtime_clear_cache(Mesh *mesh) | ||||
Not Done Inline ActionsWould be nice to add doc to this one too? mont29: Would be nice to add doc to this one too? | |||||
| { | { | ||||
| if (mesh->runtime.eval_mutex != NULL) { | |||||
| BLI_mutex_end(mesh->runtime.eval_mutex); | |||||
| MEM_freeN(mesh->runtime.eval_mutex); | |||||
| mesh->runtime.eval_mutex = NULL; | |||||
| } | |||||
| if (mesh->runtime.render_mutex != NULL) { | |||||
| BLI_mutex_end(mesh->runtime.render_mutex); | |||||
| MEM_freeN(mesh->runtime.render_mutex); | |||||
| mesh->runtime.render_mutex = NULL; | |||||
| } | |||||
| if (mesh->runtime.mesh_eval != NULL) { | if (mesh->runtime.mesh_eval != NULL) { | ||||
| mesh->runtime.mesh_eval->edit_mesh = NULL; | mesh->runtime.mesh_eval->edit_mesh = NULL; | ||||
| BKE_id_free(NULL, mesh->runtime.mesh_eval); | BKE_id_free(NULL, mesh->runtime.mesh_eval); | ||||
| mesh->runtime.mesh_eval = NULL; | mesh->runtime.mesh_eval = NULL; | ||||
| } | } | ||||
Done Inline ActionsThis also has nothing to do in a mutexes specific function. mont29: This also has nothing to do in a `mutexes` specific function. | |||||
| BKE_mesh_runtime_clear_geometry(mesh); | BKE_mesh_runtime_clear_geometry(mesh); | ||||
| BKE_mesh_batch_cache_free(mesh); | BKE_mesh_batch_cache_free(mesh); | ||||
| BKE_mesh_runtime_clear_edit_data(mesh); | BKE_mesh_runtime_clear_edit_data(mesh); | ||||
| } | } | ||||
| /* This is a ported copy of DM_ensure_looptri_data(dm) */ | /* This is a ported copy of DM_ensure_looptri_data(dm) */ | ||||
| /** | /** | ||||
| * Ensure the array is large enough | * Ensure the array is large enough | ||||
| Show All 9 Lines | static void mesh_ensure_looptri_data(Mesh *mesh) | ||||
| BLI_assert(mesh->runtime.looptris.array_wip == NULL); | BLI_assert(mesh->runtime.looptris.array_wip == NULL); | ||||
| SWAP(MLoopTri *, mesh->runtime.looptris.array, mesh->runtime.looptris.array_wip); | SWAP(MLoopTri *, mesh->runtime.looptris.array, mesh->runtime.looptris.array_wip); | ||||
| if ((looptris_len > mesh->runtime.looptris.len_alloc) || | if ((looptris_len > mesh->runtime.looptris.len_alloc) || | ||||
| (looptris_len < mesh->runtime.looptris.len_alloc * 2) || (totpoly == 0)) { | (looptris_len < mesh->runtime.looptris.len_alloc * 2) || (totpoly == 0)) { | ||||
| MEM_SAFE_FREE(mesh->runtime.looptris.array_wip); | MEM_SAFE_FREE(mesh->runtime.looptris.array_wip); | ||||
| mesh->runtime.looptris.len_alloc = 0; | mesh->runtime.looptris.len_alloc = 0; | ||||
| mesh->runtime.looptris.len = 0; | mesh->runtime.looptris.len = 0; | ||||
Done Inline ActionsCalling this here effectively wipes out the entire runtime struct, which is exactly what we do not want to do here... mont29: Calling this here effectively wipes out the entire `runtime` struct, which is exactly what we… | |||||
| } | } | ||||
| if (totpoly) { | if (totpoly) { | ||||
| if (mesh->runtime.looptris.array_wip == NULL) { | if (mesh->runtime.looptris.array_wip == NULL) { | ||||
| mesh->runtime.looptris.array_wip = MEM_malloc_arrayN( | mesh->runtime.looptris.array_wip = MEM_malloc_arrayN( | ||||
| looptris_len, sizeof(*mesh->runtime.looptris.array_wip), __func__); | looptris_len, sizeof(*mesh->runtime.looptris.array_wip), __func__); | ||||
| mesh->runtime.looptris.len_alloc = looptris_len; | mesh->runtime.looptris.len_alloc = looptris_len; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 332 Lines • Show Last 20 Lines | |||||
static functions do not take the module prefix (so just mesh_runtime_init_mutexes)