Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <mano-wii>2021-06-10 17:01:36 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-06-11 16:45:12 +0300
commit2330cec2c6a7632459c21f51723497e349a042bf (patch)
treeba4ed258743ceb269990d0352d2be87aa2aaa901 /source/blender/draw/intern/mesh_extractors
parentfe22635bf664af844933695ba3a0d79a01807818 (diff)
Refactor: Draw Cache: use 'BLI_task_parallel_range'
This is an adaptation of {D11488}. A disadvantage of manually setting the iter ranges per thread is that we don't know how many threads are running in the background and so we don't know how to best distribute the ranges. To solve this limitation we can use `parallel_reduce` and thus let the driver choose the best distribution of ranges among the threads. This proved to be especially beneficial for computers with few cores. **Benchmarking:** Here's the result on an 4-core laptop: ||master:|PATCH: |---|---|---| |large_mesh_editing:|Average: 5.203638 FPS|Average: 5.398925 FPS ||rdata 15ms iter 43ms (frame 193ms)|rdata 14ms iter 36ms (frame 187ms) Here's the result on an 8-core PC: ||master:|PATCH: |---|---|---| |large_mesh_editing:|Average: 15.267482 FPS|Average: 15.906881 FPS ||rdata 9ms iter 28ms (frame 65ms)|rdata 9ms iter 25ms (frame 63ms) |large_mesh_editing_ledge: |Average: 15.145966 FPS|Average: 15.520474 FPS ||rdata 9ms iter 29ms (frame 65ms)|rdata 9ms iter 25ms (frame 64ms) |looptris_test:|Average: 4.001917 FPS|Average: 4.061105 FPS ||rdata 12ms iter 90ms (frame 236ms)|rdata 12ms iter 87ms (frame 230ms) |subdiv_mesh_cage_and_final:|Average: 1.917769 FPS|Average: 1.971790 FPS ||rdata 7ms iter 37ms (frame 261ms)|rdata 7ms iter 31ms (frame 258ms) ||rdata 7ms iter 38ms (frame 252ms)|rdata 7ms iter 33ms (frame 249ms) |subdiv_mesh_final_only:|Average: 6.387240 FPS|Average: 6.591251 FPS ||rdata 3ms iter 25ms (frame 151ms)|rdata 3ms iter 16ms (frame 145ms) |subdiv_mesh_final_only_ledge:|Average: 6.247393 FPS|Average: 6.596024 FPS ||rdata 3ms iter 26ms (frame 158ms)|rdata 3ms iter 16ms (frame 148ms) **Notes:** - The improvement can only be noticed if all extracts are multithreaded. - This patch touches different areas of the code, so it can be split into another patch if the idea is accepted. These screenshots show how threads behave in a quadcore: Master: {F10164664} Patch: {F10164666} Differential Revision: https://developer.blender.org/D11558
Diffstat (limited to 'source/blender/draw/intern/mesh_extractors')
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc58
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc14
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc51
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc18
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc18
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc41
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc47
7 files changed, 104 insertions, 143 deletions
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
index 20b0ec738ee..565f8834ab1 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
@@ -37,15 +37,14 @@ struct MeshExtract_EditUvElem_Data {
bool sync_selection;
};
-static void *extract_edituv_tris_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_edituv_tris_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
- MEM_callocN(sizeof(*data), __func__));
+ MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(tls_data);
GPU_indexbuf_init(&data->elb, GPU_PRIM_TRIS, mr->tri_len, mr->loop_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
- return data;
}
BLI_INLINE void edituv_tri_add(
@@ -93,7 +92,6 @@ static void extract_edituv_tris_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
- MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_tris()
@@ -104,6 +102,7 @@ constexpr MeshExtract create_extractor_edituv_tris()
extractor.iter_looptri_mesh = extract_edituv_tris_iter_looptri_mesh;
extractor.finish = extract_edituv_tris_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_tris);
return extractor;
@@ -115,15 +114,14 @@ constexpr MeshExtract create_extractor_edituv_tris()
/** \name Extract Edit UV Line Indices around faces
* \{ */
-static void *extract_edituv_lines_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_edituv_lines_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
- MEM_callocN(sizeof(*data), __func__));
+ MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(tls_data);
GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES, mr->loop_len, mr->loop_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
- return data;
}
BLI_INLINE void edituv_edge_add(
@@ -135,7 +133,7 @@ BLI_INLINE void edituv_edge_add(
}
static void extract_edituv_lines_iter_poly_bm(const MeshRenderData *UNUSED(mr),
- BMFace *f,
+ const BMFace *f,
const int UNUSED(f_index),
void *_data)
{
@@ -184,7 +182,6 @@ static void extract_edituv_lines_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
- MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_lines()
@@ -195,6 +192,7 @@ constexpr MeshExtract create_extractor_edituv_lines()
extractor.iter_poly_mesh = extract_edituv_lines_iter_poly_mesh;
extractor.finish = extract_edituv_lines_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_lines);
return extractor;
@@ -206,15 +204,14 @@ constexpr MeshExtract create_extractor_edituv_lines()
/** \name Extract Edit UV Points Indices
* \{ */
-static void *extract_edituv_points_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_edituv_points_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
- MEM_callocN(sizeof(*data), __func__));
+ MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(tls_data);
GPU_indexbuf_init(&data->elb, GPU_PRIM_POINTS, mr->loop_len, mr->loop_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
- return data;
}
BLI_INLINE void edituv_point_add(MeshExtract_EditUvElem_Data *data,
@@ -228,7 +225,7 @@ BLI_INLINE void edituv_point_add(MeshExtract_EditUvElem_Data *data,
}
static void extract_edituv_points_iter_poly_bm(const MeshRenderData *UNUSED(mr),
- BMFace *f,
+ const BMFace *f,
const int UNUSED(f_index),
void *_data)
{
@@ -269,7 +266,6 @@ static void extract_edituv_points_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
- MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_points()
@@ -280,6 +276,7 @@ constexpr MeshExtract create_extractor_edituv_points()
extractor.iter_poly_mesh = extract_edituv_points_iter_poly_mesh;
extractor.finish = extract_edituv_points_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_points);
return extractor;
@@ -291,15 +288,14 @@ constexpr MeshExtract create_extractor_edituv_points()
/** \name Extract Edit UV Face-dots Indices
* \{ */
-static void *extract_edituv_fdots_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_edituv_fdots_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
- MEM_callocN(sizeof(*data), __func__));
+ MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(tls_data);
GPU_indexbuf_init(&data->elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
- return data;
}
BLI_INLINE void edituv_facedot_add(MeshExtract_EditUvElem_Data *data,
@@ -316,7 +312,7 @@ BLI_INLINE void edituv_facedot_add(MeshExtract_EditUvElem_Data *data,
}
static void extract_edituv_fdots_iter_poly_bm(const MeshRenderData *UNUSED(mr),
- BMFace *f,
+ const BMFace *f,
const int f_index,
void *_data)
{
@@ -366,7 +362,6 @@ static void extract_edituv_fdots_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
- MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_fdots()
@@ -377,6 +372,7 @@ constexpr MeshExtract create_extractor_edituv_fdots()
extractor.iter_poly_mesh = extract_edituv_fdots_iter_poly_mesh;
extractor.finish = extract_edituv_fdots_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_EditUvElem_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.edituv_fdots);
return extractor;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc
index 9bd918dc9a5..1d1a000061d 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_fdots.cc
@@ -32,17 +32,17 @@ namespace blender::draw {
/** \name Extract Face-dots Indices
* \{ */
-static void *extract_fdots_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(buf))
+static void extract_fdots_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf),
+ void *tls_data)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
+ GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(tls_data);
GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
- return elb;
}
static void extract_fdots_iter_poly_bm(const MeshRenderData *UNUSED(mr),
- BMFace *f,
+ const BMFace *f,
const int f_index,
void *_userdata)
{
@@ -93,7 +93,6 @@ static void extract_fdots_finish(const MeshRenderData *UNUSED(mr),
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
- MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_fdots()
@@ -104,6 +103,7 @@ constexpr MeshExtract create_extractor_fdots()
extractor.iter_poly_mesh = extract_fdots_iter_poly_mesh;
extractor.finish = extract_fdots_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.fdots);
return extractor;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
index 74a3d3825c5..683794d4d66 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
@@ -31,28 +31,19 @@ namespace blender::draw {
/** \name Extract Edges Indices
* \{ */
-static void *extract_lines_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(buf))
+static void extract_lines_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf),
+ void *tls_data)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
+ GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(tls_data);
/* Put loose edges at the end. */
GPU_indexbuf_init(
elb, GPU_PRIM_LINES, mr->edge_len + mr->edge_loose_len, mr->loop_len + mr->loop_loose_len);
- return elb;
-}
-
-static void *extract_lines_task_init(void *_userdata)
-{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
- GPUIndexBufBuilder *sub_builder = static_cast<GPUIndexBufBuilder *>(
- MEM_mallocN(sizeof(*sub_builder), __func__));
- GPU_indexbuf_subbuilder_init(elb, sub_builder);
- return sub_builder;
}
static void extract_lines_iter_poly_bm(const MeshRenderData *UNUSED(mr),
- BMFace *f,
+ const BMFace *f,
const int UNUSED(f_index),
void *data)
{
@@ -109,7 +100,7 @@ static void extract_lines_iter_poly_mesh(const MeshRenderData *mr,
}
static void extract_lines_iter_ledge_bm(const MeshRenderData *mr,
- BMEdge *eed,
+ const BMEdge *eed,
const int ledge_index,
void *data)
{
@@ -147,12 +138,11 @@ static void extract_lines_iter_ledge_mesh(const MeshRenderData *mr,
GPU_indexbuf_set_line_restart(elb, e_index);
}
-static void extract_lines_task_finish(void *_userdata, void *_task_userdata)
+static void extract_lines_task_finish(void *_userdata_to, void *_userdata_from)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
- GPUIndexBufBuilder *sub_builder = static_cast<GPUIndexBufBuilder *>(_task_userdata);
- GPU_indexbuf_subbuilder_finish(elb, sub_builder);
- MEM_freeN(sub_builder);
+ GPUIndexBufBuilder *elb_to = static_cast<GPUIndexBufBuilder *>(_userdata_to);
+ GPUIndexBufBuilder *elb_from = static_cast<GPUIndexBufBuilder *>(_userdata_from);
+ GPU_indexbuf_join_copies(elb_to, elb_from);
}
static void extract_lines_finish(const MeshRenderData *UNUSED(mr),
@@ -163,21 +153,20 @@ static void extract_lines_finish(const MeshRenderData *UNUSED(mr),
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
- MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_lines()
{
MeshExtract extractor = {0};
extractor.init = extract_lines_init;
- extractor.task_init = extract_lines_task_init;
extractor.iter_poly_bm = extract_lines_iter_poly_bm;
extractor.iter_poly_mesh = extract_lines_iter_poly_mesh;
extractor.iter_ledge_bm = extract_lines_iter_ledge_bm;
extractor.iter_ledge_mesh = extract_lines_iter_ledge_mesh;
- extractor.task_finish = extract_lines_task_finish;
+ extractor.task_reduce = extract_lines_task_finish;
extractor.finish = extract_lines_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines);
return extractor;
@@ -209,21 +198,20 @@ static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr,
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
extract_lines_loose_subbuffer(mr, cache);
- MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_lines_with_lines_loose()
{
MeshExtract extractor = {0};
extractor.init = extract_lines_init;
- extractor.task_init = extract_lines_task_init;
extractor.iter_poly_bm = extract_lines_iter_poly_bm;
extractor.iter_poly_mesh = extract_lines_iter_poly_mesh;
extractor.iter_ledge_bm = extract_lines_iter_ledge_bm;
extractor.iter_ledge_mesh = extract_lines_iter_ledge_mesh;
- extractor.task_finish = extract_lines_task_finish;
+ extractor.task_reduce = extract_lines_task_finish;
extractor.finish = extract_lines_with_lines_loose_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines);
return extractor;
@@ -235,14 +223,14 @@ constexpr MeshExtract create_extractor_lines_with_lines_loose()
/** \name Extract Loose Edges Sub Buffer
* \{ */
-static void *extract_lines_loose_only_init(const MeshRenderData *mr,
- struct MeshBatchCache *cache,
- void *buf)
+static void extract_lines_loose_only_init(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *buf,
+ void *UNUSED(tls_data))
{
BLI_assert(buf == cache->final.ibo.lines_loose);
UNUSED_VARS_NDEBUG(buf);
extract_lines_loose_subbuffer(mr, cache);
- return NULL;
}
constexpr MeshExtract create_extractor_lines_loose_only()
@@ -250,6 +238,7 @@ constexpr MeshExtract create_extractor_lines_loose_only()
MeshExtract extractor = {0};
extractor.init = extract_lines_loose_only_init;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = 0;
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_loose);
return extractor;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc
index 6140ae86c96..cace18b0c08 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_adjacency.cc
@@ -41,26 +41,25 @@ struct MeshExtract_LineAdjacency_Data {
EdgeHash *eh;
bool is_manifold;
/* Array to convert vert index to any loop index of this vert. */
- uint vert_to_loop[0];
+ uint *vert_to_loop;
};
-static void *extract_lines_adjacency_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(buf))
+static void extract_lines_adjacency_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf),
+ void *tls_data)
{
/* Similar to poly_to_tri_count().
* There is always (loop + triangle - 1) edges inside a polygon.
* Accumulate for all polys and you get : */
uint tess_edge_len = mr->loop_len + mr->tri_len - mr->poly_len;
- size_t vert_to_loop_size = sizeof(uint) * mr->vert_len;
+ MeshExtract_LineAdjacency_Data *data = static_cast<MeshExtract_LineAdjacency_Data *>(tls_data);
+ data->vert_to_loop = static_cast<uint *>(MEM_callocN(sizeof(uint) * mr->vert_len, __func__));
- MeshExtract_LineAdjacency_Data *data = static_cast<MeshExtract_LineAdjacency_Data *>(
- MEM_callocN(sizeof(*data) + vert_to_loop_size, __func__));
GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES_ADJ, tess_edge_len, mr->loop_len);
data->eh = BLI_edgehash_new_ex(__func__, tess_edge_len);
data->is_manifold = true;
- return data;
}
BLI_INLINE void lines_adjacency_triangle(
@@ -169,7 +168,7 @@ static void extract_lines_adjacency_finish(const MeshRenderData *UNUSED(mr),
cache->is_manifold = data->is_manifold;
GPU_indexbuf_build_in_place(&data->elb, ibo);
- MEM_freeN(data);
+ MEM_freeN(data->vert_to_loop);
}
#undef NO_EDGE
@@ -184,6 +183,7 @@ constexpr MeshExtract create_extractor_lines_adjacency()
extractor.iter_looptri_mesh = extract_lines_adjacency_iter_looptri_mesh;
extractor.finish = extract_lines_adjacency_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_LineAdjacency_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_adjacency);
return extractor;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
index 6bbd0188f65..a142692ab4e 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
@@ -37,18 +37,17 @@ namespace blender::draw {
struct MeshExtract_LinePaintMask_Data {
GPUIndexBufBuilder elb;
/** One bit per edge set if face is selected. */
- BLI_bitmap select_map[0];
+ BLI_bitmap *select_map;
};
-static void *extract_lines_paint_mask_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_lines_paint_mask_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- size_t bitmap_size = BLI_BITMAP_SIZE(mr->edge_len);
- MeshExtract_LinePaintMask_Data *data = static_cast<MeshExtract_LinePaintMask_Data *>(
- MEM_callocN(sizeof(*data) + bitmap_size, __func__));
+ MeshExtract_LinePaintMask_Data *data = static_cast<MeshExtract_LinePaintMask_Data *>(tls_data);
+ data->select_map = BLI_BITMAP_NEW(mr->edge_len, __func__);
GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES, mr->edge_len, mr->loop_len);
- return data;
}
static void extract_lines_paint_mask_iter_poly_mesh(const MeshRenderData *mr,
@@ -101,7 +100,7 @@ static void extract_lines_paint_mask_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_LinePaintMask_Data *data = static_cast<MeshExtract_LinePaintMask_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
- MEM_freeN(data);
+ MEM_freeN(data->select_map);
}
/** \} */
@@ -113,6 +112,7 @@ constexpr MeshExtract create_extractor_lines_paint_mask()
extractor.iter_poly_mesh = extract_lines_paint_mask_iter_poly_mesh;
extractor.finish = extract_lines_paint_mask_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_LinePaintMask_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_paint_mask);
return extractor;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
index 9220198d799..25d1a159f60 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
@@ -32,25 +32,16 @@ namespace blender::draw {
/* ---------------------------------------------------------------------- */
/** \name Extract Point Indices
* \{ */
-static void *extract_points_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(buf))
+static void extract_points_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf),
+ void *tls_data)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
+ GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(tls_data);
GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->vert_len, mr->loop_len + mr->loop_loose_len);
- return elb;
}
-static void *extract_points_task_init(void *_userdata)
-{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
- GPUIndexBufBuilder *sub_builder = static_cast<GPUIndexBufBuilder *>(
- MEM_mallocN(sizeof(*sub_builder), __func__));
- GPU_indexbuf_subbuilder_init(elb, sub_builder);
- return sub_builder;
-}
-
-BLI_INLINE void vert_set_bm(GPUIndexBufBuilder *elb, BMVert *eve, int l_index)
+BLI_INLINE void vert_set_bm(GPUIndexBufBuilder *elb, const BMVert *eve, int l_index)
{
const int v_index = BM_elem_index_get(eve);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
@@ -78,7 +69,7 @@ BLI_INLINE void vert_set_mesh(GPUIndexBufBuilder *elb,
}
static void extract_points_iter_poly_bm(const MeshRenderData *UNUSED(mr),
- BMFace *f,
+ const BMFace *f,
const int UNUSED(f_index),
void *_userdata)
{
@@ -107,7 +98,7 @@ static void extract_points_iter_poly_mesh(const MeshRenderData *mr,
}
static void extract_points_iter_ledge_bm(const MeshRenderData *mr,
- BMEdge *eed,
+ const BMEdge *eed,
const int ledge_index,
void *_userdata)
{
@@ -127,7 +118,7 @@ static void extract_points_iter_ledge_mesh(const MeshRenderData *mr,
}
static void extract_points_iter_lvert_bm(const MeshRenderData *mr,
- BMVert *eve,
+ const BMVert *eve,
const int lvert_index,
void *_userdata)
{
@@ -146,12 +137,11 @@ static void extract_points_iter_lvert_mesh(const MeshRenderData *mr,
vert_set_mesh(elb, mr, mr->lverts[lvert_index], offset + lvert_index);
}
-static void extract_points_task_finish(void *_userdata, void *_task_userdata)
+static void extract_points_task_finish(void *_userdata_to, void *_userdata_from)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
- GPUIndexBufBuilder *sub_builder = static_cast<GPUIndexBufBuilder *>(_task_userdata);
- GPU_indexbuf_subbuilder_finish(elb, sub_builder);
- MEM_freeN(sub_builder);
+ GPUIndexBufBuilder *elb_to = static_cast<GPUIndexBufBuilder *>(_userdata_to);
+ GPUIndexBufBuilder *elb_from = static_cast<GPUIndexBufBuilder *>(_userdata_from);
+ GPU_indexbuf_join_copies(elb_to, elb_from);
}
static void extract_points_finish(const MeshRenderData *UNUSED(mr),
@@ -162,24 +152,23 @@ static void extract_points_finish(const MeshRenderData *UNUSED(mr),
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
- MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_points()
{
MeshExtract extractor = {0};
extractor.init = extract_points_init;
- extractor.task_init = extract_points_task_init;
extractor.iter_poly_bm = extract_points_iter_poly_bm;
extractor.iter_poly_mesh = extract_points_iter_poly_mesh;
extractor.iter_ledge_bm = extract_points_iter_ledge_bm;
extractor.iter_ledge_mesh = extract_points_iter_ledge_mesh;
extractor.iter_lvert_bm = extract_points_iter_lvert_bm;
extractor.iter_lvert_mesh = extract_points_iter_lvert_mesh;
- extractor.task_finish = extract_points_task_finish;
+ extractor.task_reduce = extract_points_task_finish;
extractor.finish = extract_points_finish;
extractor.use_threading = true;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.points);
return extractor;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
index acfffdacb88..27929fa8ba3 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_tris.cc
@@ -37,12 +37,12 @@ struct MeshExtract_Tri_Data {
int *tri_mat_end;
};
-static void *extract_tris_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_tris_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- MeshExtract_Tri_Data *data = static_cast<MeshExtract_Tri_Data *>(
- MEM_callocN(sizeof(*data), __func__));
+ MeshExtract_Tri_Data *data = static_cast<MeshExtract_Tri_Data *>(tls_data);
size_t mat_tri_idx_size = sizeof(int) * mr->mat_len;
data->tri_mat_start = static_cast<int *>(MEM_callocN(mat_tri_idx_size, __func__));
@@ -82,8 +82,6 @@ static void *extract_tris_init(const MeshRenderData *mr,
int visible_tri_tot = ofs;
GPU_indexbuf_init(&data->elb, GPU_PRIM_TRIS, visible_tri_tot, mr->loop_len);
-
- return data;
}
static void extract_tris_iter_looptri_bm(const MeshRenderData *mr,
@@ -150,7 +148,6 @@ static void extract_tris_finish(const MeshRenderData *mr,
}
MEM_freeN(data->tri_mat_start);
MEM_freeN(data->tri_mat_end);
- MEM_freeN(data);
}
constexpr MeshExtract create_extractor_tris()
@@ -161,6 +158,7 @@ constexpr MeshExtract create_extractor_tris()
extractor.iter_looptri_mesh = extract_tris_iter_looptri_mesh;
extractor.finish = extract_tris_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(MeshExtract_Tri_Data);
extractor.use_threading = false;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.tris);
return extractor;
@@ -171,22 +169,13 @@ constexpr MeshExtract create_extractor_tris()
/** \name Extract Triangles Indices (single material)
* \{ */
-static void *extract_tris_single_mat_init(const MeshRenderData *mr,
- struct MeshBatchCache *UNUSED(cache),
- void *UNUSED(ibo))
+static void extract_tris_single_mat_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo),
+ void *tls_data)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
+ GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(tls_data);
GPU_indexbuf_init(elb, GPU_PRIM_TRIS, mr->tri_len, mr->loop_len);
- return elb;
-}
-
-static void *extract_tris_single_mat_task_init(void *_userdata)
-{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
- GPUIndexBufBuilder *sub_builder = static_cast<GPUIndexBufBuilder *>(
- MEM_mallocN(sizeof(*sub_builder), __func__));
- GPU_indexbuf_subbuilder_init(elb, sub_builder);
- return sub_builder;
}
static void extract_tris_single_mat_iter_looptri_bm(const MeshRenderData *UNUSED(mr),
@@ -222,12 +211,11 @@ static void extract_tris_single_mat_iter_looptri_mesh(const MeshRenderData *mr,
}
}
-static void extract_tris_single_mat_task_finish(void *_userdata, void *_task_userdata)
+static void extract_tris_single_mat_task_finish(void *_userdata_to, void *_userdata_from)
{
- GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
- GPUIndexBufBuilder *sub_builder = static_cast<GPUIndexBufBuilder *>(_task_userdata);
- GPU_indexbuf_subbuilder_finish(elb, sub_builder);
- MEM_freeN(sub_builder);
+ GPUIndexBufBuilder *elb_to = static_cast<GPUIndexBufBuilder *>(_userdata_to);
+ GPUIndexBufBuilder *elb_from = static_cast<GPUIndexBufBuilder *>(_userdata_from);
+ GPU_indexbuf_join_copies(elb_to, elb_from);
}
static void extract_tris_single_mat_finish(const MeshRenderData *mr,
@@ -254,19 +242,18 @@ static void extract_tris_single_mat_finish(const MeshRenderData *mr,
GPU_indexbuf_create_subrange_in_place(mbc->tris_per_mat[i], ibo, 0, len);
}
}
- MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_tris_single_mat()
{
MeshExtract extractor = {0};
extractor.init = extract_tris_single_mat_init;
- extractor.task_init = extract_tris_single_mat_task_init;
extractor.iter_looptri_bm = extract_tris_single_mat_iter_looptri_bm;
extractor.iter_looptri_mesh = extract_tris_single_mat_iter_looptri_mesh;
- extractor.task_finish = extract_tris_single_mat_task_finish;
+ extractor.task_reduce = extract_tris_single_mat_task_finish;
extractor.finish = extract_tris_single_mat_finish;
extractor.data_type = MR_DATA_NONE;
+ extractor.data_size = sizeof(GPUIndexBufBuilder);
extractor.use_threading = true;
extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.tris);
return extractor;