[Bf-blender-cvs] [98c66267299] master: DrawManager: Use CPP for Mesh Extraction Scheduling.
Jeroen Bakker
noreply at git.blender.org
Tue Jun 1 13:18:50 CEST 2021
Commit: 98c662672998a16a7ac00ab283357de17f3ae54c
Author: Jeroen Bakker
Date: Tue Jun 1 12:12:13 2021 +0200
Branches: master
https://developer.blender.org/rB98c662672998a16a7ac00ab283357de17f3ae54c
DrawManager: Use CPP for Mesh Extraction Scheduling.
More cleanups will come to make this more CPP-like.
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/intern/draw_cache_extract.h
R065 source/blender/draw/intern/draw_cache_extract_mesh.c source/blender/draw/intern/draw_cache_extract_mesh.cc
M source/blender/draw/intern/draw_cache_extract_mesh_private.h
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index adbe7fdf274..d6598bf79b0 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -53,7 +53,7 @@ set(SRC
intern/draw_cache.c
intern/draw_cache_extract_mesh_extractors.c
intern/draw_cache_extract_mesh_render_data.c
- intern/draw_cache_extract_mesh.c
+ intern/draw_cache_extract_mesh.cc
intern/draw_cache_impl_curve.cc
intern/draw_cache_impl_displist.c
intern/draw_cache_impl_gpencil.c
diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h
index abba3aeeb70..36756616ca7 100644
--- a/source/blender/draw/intern/draw_cache_extract.h
+++ b/source/blender/draw/intern/draw_cache_extract.h
@@ -68,13 +68,13 @@ typedef struct DRW_MeshCDMask {
* bit-wise and atomic operations are used to compare and update the struct.
* See `mesh_cd_layers_type_*` functions. */
BLI_STATIC_ASSERT(sizeof(DRW_MeshCDMask) <= sizeof(uint64_t), "DRW_MeshCDMask exceeds 64 bits")
-
typedef enum eMRIterType {
MR_ITER_LOOPTRI = 1 << 0,
MR_ITER_POLY = 1 << 1,
MR_ITER_LEDGE = 1 << 2,
MR_ITER_LVERT = 1 << 3,
} eMRIterType;
+ENUM_OPERATORS(eMRIterType, MR_ITER_LVERT)
typedef enum eMRDataType {
MR_DATA_POLY_NOR = 1 << 1,
@@ -83,6 +83,11 @@ typedef enum eMRDataType {
/** Force loop normals calculation. */
MR_DATA_TAN_LOOP_NOR = 1 << 4,
} eMRDataType;
+ENUM_OPERATORS(eMRDataType, MR_DATA_TAN_LOOP_NOR)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
BLI_INLINE int mesh_render_mat_len_get(Mesh *me)
{
@@ -298,3 +303,7 @@ void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
const Scene *scene,
const ToolSettings *ts,
const bool use_hide);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.cc
similarity index 65%
rename from source/blender/draw/intern/draw_cache_extract_mesh.c
rename to source/blender/draw/intern/draw_cache_extract_mesh.cc
index 0d2a4704b1b..b3ebce98524 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.cc
@@ -30,6 +30,7 @@
#include "DNA_scene_types.h"
#include "BLI_task.h"
+#include "BLI_vector.hh"
#include "BKE_editmesh.h"
@@ -47,79 +48,64 @@
#define CHUNK_SIZE 8192
+namespace blender::draw {
+
/* ---------------------------------------------------------------------- */
/** \name Mesh Elements Extract Struct
* \{ */
-typedef struct MeshExtractRunData {
+struct MeshExtractRunData {
const MeshExtract *extractor;
void *buffer;
void *user_data;
-} MeshExtractRunData;
-
-typedef struct MeshExtractRunDataArray {
- int len;
- MeshExtractRunData items[M_EXTRACT_LEN];
-} MeshExtractRunDataArray;
+};
-static void mesh_extract_run_data_array_init(MeshExtractRunDataArray *array)
-{
- array->len = 0;
-}
+using MeshExtractRunDataArray = blender::Vector<MeshExtractRunData>;
-static void mesh_extract_run_data_array_add_ex(MeshExtractRunDataArray *array,
- const MeshExtractRunData *run_data)
-{
- array->items[array->len] = *run_data;
- array->len++;
-}
-
-static void mesh_extract_run_data_array_add(MeshExtractRunDataArray *array,
+static void mesh_extract_run_data_array_add(MeshExtractRunDataArray &array,
const MeshExtract *extractor)
{
MeshExtractRunData run_data;
run_data.extractor = extractor;
run_data.buffer = NULL;
run_data.user_data = NULL;
- mesh_extract_run_data_array_add_ex(array, &run_data);
+ array.append(run_data);
}
-static void mesh_extract_run_data_array_filter_iter_type(const MeshExtractRunDataArray *src,
- MeshExtractRunDataArray *dst,
+static void mesh_extract_run_data_array_filter_iter_type(const MeshExtractRunDataArray &src,
+ MeshExtractRunDataArray &dst,
eMRIterType iter_type)
{
- for (int i = 0; i < src->len; i++) {
-
- const MeshExtractRunData *data = &src->items[i];
- const MeshExtract *extractor = data->extractor;
+ for (const MeshExtractRunData &data : src) {
+ const MeshExtract *extractor = data.extractor;
if ((iter_type & MR_ITER_LOOPTRI) && extractor->iter_looptri_bm) {
BLI_assert(extractor->iter_looptri_mesh);
- mesh_extract_run_data_array_add_ex(dst, data);
+ dst.append(data);
continue;
}
if ((iter_type & MR_ITER_POLY) && extractor->iter_poly_bm) {
BLI_assert(extractor->iter_poly_mesh);
- mesh_extract_run_data_array_add_ex(dst, data);
+ dst.append(data);
continue;
}
if ((iter_type & MR_ITER_LEDGE) && extractor->iter_ledge_bm) {
BLI_assert(extractor->iter_ledge_mesh);
- mesh_extract_run_data_array_add_ex(dst, data);
+ dst.append(data);
continue;
}
if ((iter_type & MR_ITER_LVERT) && extractor->iter_lvert_bm) {
BLI_assert(extractor->iter_lvert_mesh);
- mesh_extract_run_data_array_add_ex(dst, data);
+ dst.append(data);
continue;
}
}
}
static void mesh_extract_run_data_array_filter_threading(
- const MeshExtractRunDataArray *src, MeshExtractRunDataArray *dst_multi_threaded)
+ const MeshExtractRunDataArray &src, MeshExtractRunDataArray &dst_multi_threaded)
{
- for (int i = 0; i < src->len; i++) {
- const MeshExtract *extractor = src->items[i].extractor;
+ for (const MeshExtractRunData &data : src) {
+ const MeshExtract *extractor = data.extractor;
if (extractor->use_threading) {
mesh_extract_run_data_array_add(dst_multi_threaded, extractor);
}
@@ -132,15 +118,15 @@ static void mesh_extract_run_data_array_filter_threading(
/** \name Extract
* \{ */
-static void extracts_flags_get(const MeshExtractRunDataArray *extractors,
+static void extracts_flags_get(const MeshExtractRunDataArray &extractors,
eMRIterType *r_iter_type,
eMRDataType *r_data_flag)
{
- eMRIterType iter_type = 0;
- eMRDataType data_flag = 0;
+ eMRIterType iter_type = static_cast<eMRIterType>(0);
+ eMRDataType data_flag = static_cast<eMRDataType>(0);
- for (int i = 0; i < extractors->len; i++) {
- const MeshExtract *extractor = extractors->items[i].extractor;
+ for (const MeshExtractRunData &data : extractors) {
+ const MeshExtract *extractor = data.extractor;
iter_type |= mesh_extract_iter_type(extractor);
data_flag |= extractor->data_flag;
}
@@ -155,31 +141,28 @@ static void extracts_flags_get(const MeshExtractRunDataArray *extractors,
BLI_INLINE void extract_init(const MeshRenderData *mr,
struct MeshBatchCache *cache,
- MeshExtractRunDataArray *extractors,
+ MeshExtractRunDataArray &extractors,
MeshBufferCache *mbc)
{
/* Multi thread. */
- for (int i = 0; i < extractors->len; i++) {
- MeshExtractRunData *run_data = &extractors->items[i];
- const MeshExtract *extractor = run_data->extractor;
- run_data->buffer = mesh_extract_buffer_get(extractor, mbc);
- run_data->user_data = extractor->init(mr, cache, run_data->buffer);
+ for (MeshExtractRunData &run_data : extractors) {
+ const MeshExtract *extractor = run_data.extractor;
+ run_data.buffer = mesh_extract_buffer_get(extractor, mbc);
+ run_data.user_data = extractor->init(mr, cache, run_data.buffer);
}
}
BLI_INLINE void extract_iter_looptri_bm(const MeshRenderData *mr,
const ExtractTriBMesh_Params *params,
- const MeshExtractRunDataArray *_extractors)
+ const MeshExtractRunDataArray &all_extractors)
{
MeshExtractRunDataArray extractors;
- mesh_extract_run_data_array_init(&extractors);
- mesh_extract_run_data_array_filter_iter_type(_extractors, &extractors, MR_ITER_LOOPTRI);
+ mesh_extract_run_data_array_filter_iter_type(all_extractors, extractors, MR_ITER_LOOPTRI);
EXTRACT_TRIS_LOOPTRI_FOREACH_BM_BEGIN(elt, elt_index, params)
{
- for (int i = 0; i < extractors.len; i++) {
- MeshExtractRunData *run_data = &extractors.items[i];
- run_data->extractor->iter_looptri_bm(mr, elt, elt_index, run_data->user_data);
+ for (MeshExtractRunData &run_data : extractors) {
+ run_data.extractor->iter_looptri_bm(mr, elt, elt_index, run_data.user_data);
}
}
EXTRACT_TRIS_LOOPTRI_FOREACH_BM_END;
@@ -187,17 +170,15 @@ BLI_INLINE void extract_iter_looptri_bm(const MeshRenderData *mr,
BLI_INLINE void extract_iter_looptri_mesh(const MeshRenderData *mr,
const ExtractTriMesh_Params *params,
- const MeshExtractRunDataArray *_extractors)
+ const MeshExtractRunDataArray &all_extractors)
{
MeshExtractRunDataArray extractors;
- mesh_extract_run_data_array_init(&extractors);
- mesh_extract_run_data_array_filter_iter_type(_extractors, &extractors, MR_ITER_LOOPTRI);
+ mesh_extract_run_data_array_filter_iter_type(all_extractors, extractors, MR_ITER_LOOPTRI);
EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_BEGIN(mlt, mlt_index, params)
{
- for (int i = 0; i < extractors.len; i++) {
- MeshExtractRunData *run_data = &extractors.items[i];
- run_data->extractor->iter_looptri_mesh(mr, mlt, mlt_index, run_data->user_data);
+ for (MeshExtractRunData &run_data : extractors) {
+ run_data.extractor->iter_looptri_mesh(mr, mlt, mlt_index, run_data.user_data);
}
}
EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_END;
@@ -205,17 +186,15 @@ BLI_INLINE void extract_iter_looptri_mesh(const MeshRenderData *mr,
BLI_INLINE void extract_iter_poly_bm(const MeshRenderData *mr,
const ExtractPol
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list