[Bf-blender-cvs] [0ebc0626042] lineart-object-load: LineArt: Edge neighbor with object loading code WIP
YimingWu
noreply at git.blender.org
Mon Apr 25 10:56:17 CEST 2022
Commit: 0ebc0626042cb70ff97082ef2c40a95b50a0a68e
Author: YimingWu
Date: Mon Apr 25 14:54:07 2022 +0800
Branches: lineart-object-load
https://developer.blender.org/rB0ebc0626042cb70ff97082ef2c40a95b50a0a68e
LineArt: Edge neighbor with object loading code WIP
===================================================================
M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
===================================================================
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index dd08fc6493f..88ac80e153f 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1514,7 +1514,6 @@ typedef struct EdgeFeatData {
LineartRenderBuffer *rb;
Mesh *me;
const MLoopTri *mlooptri;
- EdgeFacePair *edge_pair_arr;
LineartTriangle *tri_array;
LineartVert *v_array;
float crease_threshold;
@@ -1522,6 +1521,7 @@ typedef struct EdgeFeatData {
bool use_auto_smooth;
bool use_freestyle_face;
int freestyle_face_index;
+ LineartEdgeNeighbor *en;
} EdgeFeatData;
typedef struct EdgeFeatReduceData {
@@ -1537,18 +1537,22 @@ static void feat_data_sum_reduce(const void *__restrict UNUSED(userdata),
feat_chunk_join->feat_edges += feat_chunk->feat_edges;
}
-static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
- const int i,
- const TaskParallelTLS *__restrict tls)
+__attribute__((optimize("O0"))) static void lineart_identify_mlooptri_feature_edges(
+ void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
{
EdgeFeatData *e_feat_data = (EdgeFeatData *)userdata;
- EdgeFacePair *e_f_pair = &e_feat_data->edge_pair_arr[i];
EdgeFeatReduceData *reduce_data = (EdgeFeatReduceData *)tls->userdata_chunk;
Mesh *me = e_feat_data->me;
+ LineartEdgeNeighbor *en = e_feat_data->en;
const MLoopTri *mlooptri = e_feat_data->mlooptri;
uint16_t edge_flag_result = 0;
+ /* Only add one from two pairs of mlooptri edges. */
+ if (i < en[i].e) {
+ return;
+ }
+
FreestyleEdge *fel, *fer;
bool face_mark_filtered = false;
bool enable_face_mark = (e_feat_data->use_freestyle_face && e_feat_data->rb->filter_face_mark);
@@ -1556,10 +1560,10 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
if (enable_face_mark) {
int index = e_feat_data->freestyle_face_index;
if (index > -1) {
- fel = &((FreestyleEdge *)me->pdata.layers[index].data)[mlooptri[e_f_pair->f1].poly];
+ fel = &((FreestyleEdge *)me->pdata.layers[index].data)[mlooptri[i / 3].poly];
}
- if (e_f_pair->f2 != -1) {
- fer = &((FreestyleEdge *)me->pdata.layers[index].data)[mlooptri[e_f_pair->f2].poly];
+ if (en[i].e > -1) {
+ fer = &((FreestyleEdge *)me->pdata.layers[index].data)[mlooptri[en[i].e / 3].poly];
}
else {
/* Handles mesh boundary case */
@@ -1579,7 +1583,7 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
face_mark_filtered = !face_mark_filtered;
}
if (!face_mark_filtered) {
- e_f_pair->eflag = LRT_EDGE_FLAG_INHIBIT;
+ en[i].flags = LRT_EDGE_FLAG_INHIBIT;
if (e_feat_data->rb->filter_face_mark_keep_contour) {
only_contour = true;
}
@@ -1592,8 +1596,8 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
else {
/* Mesh boundary */
- if (e_f_pair->f2 == -1) {
- e_f_pair->eflag = LRT_EDGE_FLAG_CONTOUR;
+ if (en[i].e == -1) {
+ en[i].flags = LRT_EDGE_FLAG_CONTOUR;
reduce_data->feat_edges += 1;
return;
}
@@ -1602,11 +1606,13 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
LineartVert *vert;
LineartRenderBuffer *rb = e_feat_data->rb;
+ int f1 = i / 3, f2 = en[i].e / 3;
+
/* The mesh should already be triangulated now, so we can assume each face is a triangle. */
- tri1 = lineart_triangle_from_index(rb, e_feat_data->tri_array, e_f_pair->f1);
- tri2 = lineart_triangle_from_index(rb, e_feat_data->tri_array, e_f_pair->f2);
+ tri1 = lineart_triangle_from_index(rb, e_feat_data->tri_array, f1);
+ tri2 = lineart_triangle_from_index(rb, e_feat_data->tri_array, f2);
- vert = &e_feat_data->v_array[e_f_pair->v1];
+ vert = &e_feat_data->v_array[en[i].v1];
double vv[3];
double *view_vector = vv;
@@ -1632,8 +1638,8 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
if (rb->use_crease) {
bool do_crease = true;
if (!rb->force_crease && !e_feat_data->use_auto_smooth &&
- (me->mpoly[mlooptri[e_f_pair->f1].poly].flag & ME_SMOOTH) &&
- (me->mpoly[mlooptri[e_f_pair->f2].poly].flag & ME_SMOOTH)) {
+ (me->mpoly[mlooptri[f1].poly].flag & ME_SMOOTH) &&
+ (me->mpoly[mlooptri[f2].poly].flag & ME_SMOOTH)) {
do_crease = false;
}
if (do_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < e_feat_data->crease_threshold)) {
@@ -1641,8 +1647,8 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
}
}
- int mat1 = me->mpoly[mlooptri[e_f_pair->f1].poly].mat_nr;
- int mat2 = me->mpoly[mlooptri[e_f_pair->f2].poly].mat_nr;
+ int mat1 = me->mpoly[mlooptri[f1].poly].mat_nr;
+ int mat2 = me->mpoly[mlooptri[f2].poly].mat_nr;
if (rb->use_material && mat1 != mat2) {
edge_flag_result |= LRT_EDGE_FLAG_MATERIAL;
@@ -1654,7 +1660,7 @@ static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata,
}
}
- e_f_pair->eflag = edge_flag_result;
+ en[i].flags = edge_flag_result;
if (edge_flag_result) {
/* Only allocate for feature edge (instead of all edges) to save memory.
@@ -1708,23 +1714,20 @@ __attribute__((optimize("O0"))) static uint16_t lineart_identify_feature_line_me
MPoly *ll = NULL, *lr = NULL;
- int t1i = -1, t1e = -1, t2i = -1;
+ int t1i = eindex / 3, t2i = -1;
if (en[eindex].e >= 0) {
- t1i = en[eindex].e / 3;
- t1e = en[eindex].e;
- }
- if (t1e >= 0 && en[t1e].e >= 0) {
- t2i = en[t1e].e / 3;
+ t2i = en[t1i].e / 3;
}
- if (t1i >= 0) {
- ll = &me->mpoly[me->runtime.looptris.array[t1i].poly];
- }
+ ll = &me->mpoly[me->runtime.looptris.array[t1i].poly];
+
if (t2i >= 0) {
lr = &me->mpoly[me->runtime.looptris.array[t2i].poly];
}
- if (t1i < 0 && t2i < 0) {
+ /* Because this function is called through looptris, so it's not really possible that both
+ * adjacent triangles are not present. */
+ if (UNLIKELY(t1i < 0 && t2i < 0)) {
if (!rb->use_loose_as_contour) {
if (use_freestyle_face && rb->filter_face_mark) {
if (rb->filter_face_mark_invert) {
@@ -1925,16 +1928,8 @@ typedef struct TriData {
LineartTriangle *tri_arr;
int lineart_triangle_size;
LineartTriangleAdjacent *tri_adj;
- LineartEdgeNeighbor *en;
} TriData;
-typedef struct TriDataReduce {
- EdgeHash *edge_hash;
- EdgeFacePair *edge_pair_arr;
- int arr_cur_len;
- int arr_alloc_len;
-} TriDataReduce;
-
static void lineart_load_tri_task(void *__restrict userdata,
const int i,
const TaskParallelTLS *__restrict tls)
@@ -1983,91 +1978,6 @@ static void lineart_load_tri_task(void *__restrict userdata,
/* Re-use this field to refer to adjacent info, will be cleared after culling stage. */
tri->intersecting_verts = (void *)&tri_task_data->tri_adj[i];
-
- TriDataReduce *reduce_data = (TriDataReduce *)tls->userdata_chunk;
- /* Initialize the edgehash if it hasn't been allocated already. */
- if (reduce_data->edge_hash == NULL) {
- reduce_data->edge_hash = BLI_edgehash_new_ex("lineart mesh conv", 256);
- }
- if (reduce_data->edge_pair_arr == NULL) {
- reduce_data->edge_pair_arr = MEM_mallocN(sizeof(EdgeFacePair) * 256, "lineart tri_pair_arr");
- reduce_data->arr_alloc_len = 256;
- }
- EdgeFacePair *edge_pair_arr = reduce_data->edge_pair_arr;
-
- /* Add the triangle edge to the edge hash. */
- for (int e = 0; e < 3; e++) {
- v1 = me->mloop[mlooptri->tri[e]].v;
- v2 = me->mloop[mlooptri->tri[(e + 1) % 3]].v;
- void **eval;
- if (!BLI_edgehash_ensure_p(reduce_data->edge_hash, v1, v2, &eval)) {
- int pair_idx = reduce_data->arr_cur_len++;
- /* Edge has not been added before, create a new pair. */
- EdgeFacePair *pair = &edge_pair_arr[pair_idx];
- pair->v1 = v1;
- pair->v2 = v2;
- pair->f1 = i;
- pair->f2 = -1;
- pair->eflag = 0;
- *eval = POINTER_FROM_INT(pair_idx);
-
- if (reduce_data->arr_cur_len == reduce_data->arr_alloc_len) {
- /* Allocate more space for our array. */
- reduce_data->arr_alloc_len *= 2;
- void *arr_tmp = MEM_mallocN(sizeof(EdgeFacePair) * reduce_data->arr_alloc_len,
- "lineart tri_pair_arr");
- memcpy(arr_tmp, edge_pair_arr, sizeof(EdgeFacePair) * reduce_data->arr_cur_len);
- MEM_freeN(edge_pair_arr);
- reduce_data->edge_pair_arr = edge_pair_arr = arr_tmp;
- }
- }
- else {
- /* The edge has already been added, set the second triangle to the current one. */
- EdgeFacePair *val = &edge_pair_arr[POINTER_AS_INT(*eval)];
- val->f2 = i;
- }
- }
-}
-
-static void lineart_load_tri_reduce(const void *__restrict UNUSED(userdata),
- void *__restrict chunk_join,
- void *__restrict chunk)
-{
- TriDataReduce *data_reduce = (TriDataReduce *)chunk;
- TriDataReduce *data_reduce_join = (TriDataReduce *)chunk_join;
- EdgeFacePair *edge_pair = data_reduce->edge_pair_arr;
-
- for (int i = 0; i < data_reduce->arr_cur_len; i++, edge_pair++) {
- void **eval;
- if (!BLI_edgehash_ensure_p(data_reduce_join->edge_hash, edge_pair->v1, edge_pair->v2, &eval)) {
- int pair_idx = data_reduce_join->arr_cur_len++;
- /* Edge has not been added in the other thread, add the pair. */
- EdgeFacePair *pair = &data_reduce_join->edge_pair_arr[pair_idx];
- memcpy(pair, edge_pair, sizeof(EdgeFacePair));
- *eval = POINTER_FROM_INT(pair_idx);
-
- if (data_reduce_join->arr_cur_len == data_reduce_join->arr_alloc_len) {
- /* Allocate more space for our array. */
- data_reduce_join->arr_alloc_len *= 2;
- void *arr_tmp = MEM_mallocN(sizeof(EdgeFacePair)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list