diff options
author | Hans Goudey <h.goudey@me.com> | 2022-10-13 06:31:02 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-10-13 06:31:50 +0300 |
commit | c67e5628d22f8348492b6205081fe1798d50689c (patch) | |
tree | 01b7b5e46f080f0359c06b389d7d1a544279e325 /source/blender/draw | |
parent | 375dafe3ef40eb61e831902a1ae45ecca555fec6 (diff) |
Cleanup: Use std::mutex for mesh runtime mutexes
Instead of allocating three separate ThreadMutex pointers,
just embed std::mutex into the struct directly.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/intern/draw_attributes.cc | 7 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_attributes.h | 8 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_curves.cc | 20 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.cc | 14 |
4 files changed, 22 insertions, 27 deletions
diff --git a/source/blender/draw/intern/draw_attributes.cc b/source/blender/draw/intern/draw_attributes.cc index 011d72e9e8f..cc7c9959850 100644 --- a/source/blender/draw/intern/draw_attributes.cc +++ b/source/blender/draw/intern/draw_attributes.cc @@ -44,13 +44,10 @@ void drw_attributes_clear(DRW_Attributes *attributes) memset(attributes, 0, sizeof(DRW_Attributes)); } -void drw_attributes_merge(DRW_Attributes *dst, - const DRW_Attributes *src, - ThreadMutex *render_mutex) +void drw_attributes_merge(DRW_Attributes *dst, const DRW_Attributes *src, std::mutex &render_mutex) { - BLI_mutex_lock(render_mutex); + std::lock_guard lock{render_mutex}; drw_attributes_merge_requests(src, dst); - BLI_mutex_unlock(render_mutex); } bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b) diff --git a/source/blender/draw/intern/draw_attributes.h b/source/blender/draw/intern/draw_attributes.h index 786301d0164..00621c711bf 100644 --- a/source/blender/draw/intern/draw_attributes.h +++ b/source/blender/draw/intern/draw_attributes.h @@ -9,6 +9,10 @@ #pragma once +#ifdef __cplusplus +# include <mutex> +#endif + #include "DNA_customdata_types.h" #include "DNA_meshdata_types.h" @@ -56,9 +60,11 @@ BLI_STATIC_ASSERT(sizeof(DRW_MeshCDMask) <= sizeof(uint32_t), "DRW_MeshCDMask ex void drw_attributes_clear(DRW_Attributes *attributes); +#ifdef __cplusplus void drw_attributes_merge(DRW_Attributes *dst, const DRW_Attributes *src, - ThreadMutex *render_mutex); + std::mutex &render_mutex); +#endif /* Return true if all requests in b are in a. */ bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b); diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc index 33b97388620..e6a422b6a11 100644 --- a/source/blender/draw/intern/draw_cache_impl_curves.cc +++ b/source/blender/draw/intern/draw_cache_impl_curves.cc @@ -60,7 +60,7 @@ struct CurvesBatchCache { * some locking would be necessary because multiple objects can use the same curves data with * different materials, etc. This is a placeholder to make multi-threading easier in the future. */ - ThreadMutex render_mutex; + std::mutex render_mutex; }; static bool curves_batch_cache_valid(const Curves &curves) @@ -74,15 +74,13 @@ static void curves_batch_cache_init(Curves &curves) CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves.batch_cache); if (!cache) { - cache = MEM_cnew<CurvesBatchCache>(__func__); + cache = MEM_new<CurvesBatchCache>(__func__); curves.batch_cache = cache; } else { - memset(cache, 0, sizeof(*cache)); + cache = {}; } - BLI_mutex_init(&cache->render_mutex); - cache->is_dirty = false; } @@ -172,9 +170,8 @@ void DRW_curves_batch_cache_dirty_tag(Curves *curves, int mode) void DRW_curves_batch_cache_free(Curves *curves) { curves_batch_cache_clear(*curves); - CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves->batch_cache); - BLI_mutex_end(&cache->render_mutex); - MEM_SAFE_FREE(curves->batch_cache); + MEM_delete(static_cast<CurvesBatchCache *>(curves->batch_cache)); + curves->batch_cache = nullptr; } void DRW_curves_batch_cache_free_old(Curves *curves, int ctime) @@ -554,7 +551,6 @@ static bool curves_ensure_attributes(const Curves &curves, GPUMaterial *gpu_material, int subdiv) { - ThreadMutex *render_mutex = &cache.render_mutex; const CustomData *cd_curve = &curves.geometry.curve_data; const CustomData *cd_point = &curves.geometry.point_data; CurvesEvalFinalCache &final_cache = cache.curves_cache.final[subdiv]; @@ -588,9 +584,9 @@ static bool curves_ensure_attributes(const Curves &curves, GPU_VERTBUF_DISCARD_SAFE(cache.curves_cache.proc_attributes_buf[i]); DRW_TEXTURE_FREE_SAFE(cache.curves_cache.proc_attributes_tex[i]); } - drw_attributes_merge(&final_cache.attr_used, &attrs_needed, render_mutex); + drw_attributes_merge(&final_cache.attr_used, &attrs_needed, cache.render_mutex); } - drw_attributes_merge(&final_cache.attr_used_over_time, &attrs_needed, render_mutex); + drw_attributes_merge(&final_cache.attr_used_over_time, &attrs_needed, cache.render_mutex); } bool need_tf_update = false; @@ -689,7 +685,7 @@ static void request_attribute(Curves &curves, const char *name) drw_attributes_add_request( &attributes, name, type, CustomData_get_named_layer(&custom_data, type, name), domain); - drw_attributes_merge(&final_cache.attr_used, &attributes, &cache.render_mutex); + drw_attributes_merge(&final_cache.attr_used, &attributes, cache.render_mutex); } GPUTexture **DRW_curves_texture_for_evaluated_attribute(Curves *curves, diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.cc b/source/blender/draw/intern/draw_cache_impl_mesh.cc index 423d1968eed..d3e071c14e7 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.cc +++ b/source/blender/draw/intern/draw_cache_impl_mesh.cc @@ -1017,8 +1017,7 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Object *object, BLI_assert(gpumat_array_len == cache->mat_len); mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed); - ThreadMutex *mesh_render_mutex = (ThreadMutex *)me->runtime->render_mutex; - drw_attributes_merge(&cache->attr_needed, &attrs_needed, mesh_render_mutex); + drw_attributes_merge(&cache->attr_needed, &attrs_needed, me->runtime->render_mutex); mesh_batch_cache_request_surface_batches(cache); return cache->surface_per_mat; } @@ -1046,8 +1045,7 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_vertpaint(Object *object, Mesh *me) DRW_Attributes attrs_needed{}; request_active_and_default_color_attributes(*object, *me, attrs_needed); - ThreadMutex *mesh_render_mutex = (ThreadMutex *)me->runtime->render_mutex; - drw_attributes_merge(&cache->attr_needed, &attrs_needed, mesh_render_mutex); + drw_attributes_merge(&cache->attr_needed, &attrs_needed, me->runtime->render_mutex); mesh_batch_cache_request_surface_batches(cache); return cache->batch.surface; @@ -1060,8 +1058,7 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_sculpt(Object *object, Mesh *me) DRW_Attributes attrs_needed{}; request_active_and_default_color_attributes(*object, *me, attrs_needed); - ThreadMutex *mesh_render_mutex = (ThreadMutex *)me->runtime->render_mutex; - drw_attributes_merge(&cache->attr_needed, &attrs_needed, mesh_render_mutex); + drw_attributes_merge(&cache->attr_needed, &attrs_needed, me->runtime->render_mutex); mesh_batch_cache_request_surface_batches(cache); return cache->batch.surface; @@ -1446,7 +1443,6 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, } } - ThreadMutex *mesh_render_mutex = (ThreadMutex *)me->runtime->render_mutex; /* Verify that all surface batches have needed attribute layers. */ @@ -1485,12 +1481,12 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, cache->batch_ready &= ~(MBC_SURFACE); mesh_cd_layers_type_merge(&cache->cd_used, cache->cd_needed); - drw_attributes_merge(&cache->attr_used, &cache->attr_needed, mesh_render_mutex); + drw_attributes_merge(&cache->attr_used, &cache->attr_needed, me->runtime->render_mutex); } mesh_cd_layers_type_merge(&cache->cd_used_over_time, cache->cd_needed); mesh_cd_layers_type_clear(&cache->cd_needed); - drw_attributes_merge(&cache->attr_used_over_time, &cache->attr_needed, mesh_render_mutex); + drw_attributes_merge(&cache->attr_used_over_time, &cache->attr_needed, me->runtime->render_mutex); drw_attributes_clear(&cache->attr_needed); } |