diff options
author | Jeroen Bakker <jbakker> | 2021-06-08 17:35:33 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-06-08 17:36:06 +0300 |
commit | 259b9c73d067bb51a6e86ff8eadd3de30c74e5ac (patch) | |
tree | 14c4f41174763ac222bfd2bfca7e4992d858abb4 /source/blender/gpu/intern/gpu_index_buffer.cc | |
parent | 08b0de45f323ee30cea2322dc7d3bc492d6518ec (diff) |
GPU: Thread safe index buffer builders.
Current index builder is designed to be used in a single thread.
This makes all index buffer extractions single threaded.
This patch adds a thread safe solution enabling multithreaded
building of index buffers.
To reduce locking the solution would provide a task/thread local
index buffer builder (called sub builder).
When a thread is finished this thread local index buffer builder
can be joined with the initial index buffer builder.
`GPU_indexbuf_subbuilder_init`: Initialized a sub builder. The
index list is shared between the parent and sub buffer, but the
counters are localized. Ensuring that updating counters would
not need any locking.
`GPU_indexbuf_subbuilder_finish`: merge the information of the
sub builder back to the parent builder. Needs to be invoked outside
the worker thread, or when sure that all worker threads have been
finished. Internal the function is not thread safe.
For testing purposes the extract_points extractor has been migrated to
the new API. Herefore changes to the mesh extractor were needed.
* When creating tasks, the task number of current task is stored in
ExtractTaskData including the total number of tasks.
* Adding two functions in `MeshExtract`.
** `task_init` will initialize the task specific userdata.
** `task_finish` should merge back the task specific userdata back.
* adding task_id parameter to the iteration functions so they can
access the correct task data without any need for locking.
There is no noticeable change in end user performance.
Reviewed By: mano-wii
Differential Revision: https://developer.blender.org/D11499
Diffstat (limited to 'source/blender/gpu/intern/gpu_index_buffer.cc')
-rw-r--r-- | source/blender/gpu/intern/gpu_index_buffer.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc index 9f283a3a944..3cdcaac5544 100644 --- a/source/blender/gpu/intern/gpu_index_buffer.cc +++ b/source/blender/gpu/intern/gpu_index_buffer.cc @@ -25,6 +25,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_math_base.h" #include "BLI_utildefines.h" #include "gpu_backend.hh" @@ -56,6 +57,7 @@ void GPU_indexbuf_init_ex(GPUIndexBufBuilder *builder, builder->index_max = 0; builder->prim_type = prim_type; builder->data = (uint *)MEM_callocN(builder->max_index_len * sizeof(uint), "GPUIndexBuf data"); + builder->parent = nullptr; } void GPU_indexbuf_init(GPUIndexBufBuilder *builder, @@ -78,6 +80,23 @@ GPUIndexBuf *GPU_indexbuf_build_on_device(uint index_len) return elem_; } +void GPU_indexbuf_subbuilder_init(const GPUIndexBufBuilder *parent_builder, + GPUIndexBufBuilder *sub_builder) +{ + BLI_assert(parent_builder->parent == nullptr); + memcpy(sub_builder, parent_builder, sizeof(GPUIndexBufBuilder)); + sub_builder->parent = parent_builder; +} + +void GPU_indexbuf_subbuilder_finish(GPUIndexBufBuilder *parent_builder, + const GPUIndexBufBuilder *sub_builder) +{ + BLI_assert(parent_builder == sub_builder->parent); + parent_builder->index_len = max_uu(parent_builder->index_len, sub_builder->index_len); + parent_builder->index_min = min_uu(parent_builder->index_min, sub_builder->index_min); + parent_builder->index_max = max_uu(parent_builder->index_max, sub_builder->index_max); +} + void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *builder, uint v) { #if TRUST_NO_ONE |