diff options
author | Joseph Eagar <joeedh@gmail.com> | 2021-06-08 01:16:03 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2021-06-08 01:16:03 +0300 |
commit | a6715213c3929ebddc59ee9aea75ea8d9af427b8 (patch) | |
tree | 157a667ebbed527b4db1a0f78ce31213a1a66df2 /source/blender/blenkernel/intern | |
parent | 482465e18aa7c9f74fcb90ec1002f157a580e240 (diff) |
Revert "Improve multires performance."
. . .because I accidentally committed
submodule references.
This reverts commit 482465e18aa7c9f74fcb90ec1002f157a580e240.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/subdiv_ccg.c | 154 |
1 files changed, 15 insertions, 139 deletions
diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index 5f732ba91ab..a59f9e0c633 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -28,14 +28,12 @@ #include "MEM_guardedalloc.h" -#include "BLI_ghash.h" #include "BLI_math_bits.h" #include "BLI_math_vector.h" #include "BLI_task.h" #include "BKE_DerivedMesh.h" #include "BKE_ccg.h" -#include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_subdiv.h" #include "BKE_subdiv_eval.h" @@ -52,11 +50,6 @@ static void subdiv_ccg_average_inner_face_grids(SubdivCCG *subdiv_ccg, CCGKey *key, SubdivCCGFace *face); -void subdiv_ccg_average_faces_boundaries_and_corners(SubdivCCG *subdiv_ccg, - CCGKey *key, - struct CCGFace **effected_faces, - int num_effected_faces); - /** \} */ /* -------------------------------------------------------------------- */ @@ -896,12 +889,11 @@ void BKE_subdiv_ccg_update_normals(SubdivCCG *subdiv_ccg, return; } subdiv_ccg_recalc_modified_inner_grid_normals(subdiv_ccg, effected_faces, num_effected_faces); - + /* TODO(sergey): Only average elements which are adjacent to modified + * faces. */ CCGKey key; BKE_subdiv_ccg_key_top_level(&key, subdiv_ccg); - - subdiv_ccg_average_faces_boundaries_and_corners( - subdiv_ccg, &key, effected_faces, num_effected_faces); + subdiv_ccg_average_all_boundaries_and_corners(subdiv_ccg, &key); } /** \} */ @@ -1040,9 +1032,6 @@ static void subdiv_ccg_average_inner_grids_task(void *__restrict userdata_v, typedef struct AverageGridsBoundariesData { SubdivCCG *subdiv_ccg; CCGKey *key; - - /* Optional lookup table. Maps task index to index in `subdiv_ccg->adjacent_vertices`. */ - int *adjacent_edge_index_map; } AverageGridsBoundariesData; typedef struct AverageGridsBoundariesTLSData { @@ -1090,14 +1079,10 @@ static void subdiv_ccg_average_grids_boundary(SubdivCCG *subdiv_ccg, } static void subdiv_ccg_average_grids_boundaries_task(void *__restrict userdata_v, - const int n, + const int adjacent_edge_index, const TaskParallelTLS *__restrict tls_v) { AverageGridsBoundariesData *data = userdata_v; - const int adjacent_edge_index = data->adjacent_edge_index_map ? - data->adjacent_edge_index_map[n] : - n; - AverageGridsBoundariesTLSData *tls = tls_v->userdata_chunk; SubdivCCG *subdiv_ccg = data->subdiv_ccg; CCGKey *key = data->key; @@ -1115,9 +1100,6 @@ static void subdiv_ccg_average_grids_boundaries_free(const void *__restrict UNUS typedef struct AverageGridsCornerData { SubdivCCG *subdiv_ccg; CCGKey *key; - - /* Optional lookup table. Maps task range index to index in subdiv_ccg->adjacent_vertices*/ - int *adjacent_vert_index_map; } AverageGridsCornerData; static void subdiv_ccg_average_grids_corners(SubdivCCG *subdiv_ccg, @@ -1146,63 +1128,49 @@ static void subdiv_ccg_average_grids_corners(SubdivCCG *subdiv_ccg, } static void subdiv_ccg_average_grids_corners_task(void *__restrict userdata_v, - const int n, + const int adjacent_vertex_index, const TaskParallelTLS *__restrict UNUSED(tls_v)) { AverageGridsCornerData *data = userdata_v; - const int adjacent_vertex_index = data->adjacent_vert_index_map ? - data->adjacent_vert_index_map[n] : - n; SubdivCCG *subdiv_ccg = data->subdiv_ccg; CCGKey *key = data->key; SubdivCCGAdjacentVertex *adjacent_vertex = &subdiv_ccg->adjacent_vertices[adjacent_vertex_index]; subdiv_ccg_average_grids_corners(subdiv_ccg, key, adjacent_vertex); } -static void subdiv_ccg_average_boundaries(SubdivCCG *subdiv_ccg, - CCGKey *key, - int *adjacent_edge_index_map, - int num_adjacent_edges) +static void subdiv_ccg_average_all_boundaries(SubdivCCG *subdiv_ccg, CCGKey *key) { TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); AverageGridsBoundariesData boundaries_data = { - .subdiv_ccg = subdiv_ccg, .key = key, .adjacent_edge_index_map = adjacent_edge_index_map}; + .subdiv_ccg = subdiv_ccg, + .key = key, + }; AverageGridsBoundariesTLSData tls_data = {NULL}; parallel_range_settings.userdata_chunk = &tls_data; parallel_range_settings.userdata_chunk_size = sizeof(tls_data); parallel_range_settings.func_free = subdiv_ccg_average_grids_boundaries_free; BLI_task_parallel_range(0, - num_adjacent_edges, + subdiv_ccg->num_adjacent_edges, &boundaries_data, subdiv_ccg_average_grids_boundaries_task, ¶llel_range_settings); } -static void subdiv_ccg_average_all_boundaries(SubdivCCG *subdiv_ccg, CCGKey *key) -{ - subdiv_ccg_average_boundaries(subdiv_ccg, key, NULL, subdiv_ccg->num_adjacent_edges); -} - -static void subdiv_ccg_average_corners(SubdivCCG *subdiv_ccg, - CCGKey *key, - int *adjacent_vert_index_map, - int num_adjacent_vertices) +static void subdiv_ccg_average_all_corners(SubdivCCG *subdiv_ccg, CCGKey *key) { TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); AverageGridsCornerData corner_data = { - .subdiv_ccg = subdiv_ccg, .key = key, .adjacent_vert_index_map = adjacent_vert_index_map}; + .subdiv_ccg = subdiv_ccg, + .key = key, + }; BLI_task_parallel_range(0, - num_adjacent_vertices, + subdiv_ccg->num_adjacent_vertices, &corner_data, subdiv_ccg_average_grids_corners_task, ¶llel_range_settings); } -static void subdiv_ccg_average_all_corners(SubdivCCG *subdiv_ccg, CCGKey *key) -{ - subdiv_ccg_average_corners(subdiv_ccg, key, NULL, subdiv_ccg->num_adjacent_vertices); -} static void subdiv_ccg_average_all_boundaries_and_corners(SubdivCCG *subdiv_ccg, CCGKey *key) { @@ -1230,98 +1198,6 @@ void BKE_subdiv_ccg_average_grids(SubdivCCG *subdiv_ccg) subdiv_ccg_average_all_boundaries_and_corners(subdiv_ccg, &key); } -static void subdiv_ccg_affected_face_adjacency(SubdivCCG *subdiv_ccg, - struct CCGFace **effected_faces, - int num_effected_faces, - GSet *r_adjacent_vertices, - GSet *r_adjacent_edges) -{ - Subdiv *subdiv = subdiv_ccg->subdiv; - OpenSubdiv_TopologyRefiner *topology_refiner = subdiv->topology_refiner; - - StaticOrHeapIntStorage face_vertices_storage; - StaticOrHeapIntStorage face_edges_storage; - - static_or_heap_storage_init(&face_vertices_storage); - static_or_heap_storage_init(&face_edges_storage); - - for (int i = 0; i < num_effected_faces; i++) { - SubdivCCGFace *face = (SubdivCCGFace *)effected_faces[i]; - int face_index = face - subdiv_ccg->faces; - const int num_face_grids = face->num_grids; - const int num_face_edges = num_face_grids; - int *face_vertices = static_or_heap_storage_get(&face_vertices_storage, num_face_edges); - topology_refiner->getFaceVertices(topology_refiner, face_index, face_vertices); - - /* Note that order of edges is same as order of MLoops, which also - * means it's the same as order of grids. */ - int *face_edges = static_or_heap_storage_get(&face_edges_storage, num_face_edges); - topology_refiner->getFaceEdges(topology_refiner, face_index, face_edges); - for (int corner = 0; corner < num_face_edges; corner++) { - const int vertex_index = face_vertices[corner]; - const int edge_index = face_edges[corner]; - - int edge_vertices[2]; - topology_refiner->getEdgeVertices(topology_refiner, edge_index, edge_vertices); - - SubdivCCGAdjacentEdge *adjacent_edge = &subdiv_ccg->adjacent_edges[edge_index]; - BLI_gset_add(r_adjacent_edges, adjacent_edge); - - SubdivCCGAdjacentVertex *adjacent_vertex = &subdiv_ccg->adjacent_vertices[vertex_index]; - BLI_gset_add(r_adjacent_vertices, adjacent_vertex); - } - } - - static_or_heap_storage_free(&face_vertices_storage); - static_or_heap_storage_free(&face_edges_storage); -} - -void subdiv_ccg_average_faces_boundaries_and_corners(SubdivCCG *subdiv_ccg, - CCGKey *key, - struct CCGFace **effected_faces, - int num_effected_faces) -{ - GSet *adjacent_vertices = BLI_gset_ptr_new(__func__); - GSet *adjacent_edges = BLI_gset_ptr_new(__func__); - GSetIterator gi; - - subdiv_ccg_affected_face_adjacency( - subdiv_ccg, effected_faces, num_effected_faces, adjacent_vertices, adjacent_edges); - - int *adjacent_vertex_index_map; - int *adjacent_edge_index_map; - - StaticOrHeapIntStorage index_heap; - static_or_heap_storage_init(&index_heap); - - int i = 0; - - /* Average boundaries. */ - - adjacent_edge_index_map = static_or_heap_storage_get(&index_heap, BLI_gset_len(adjacent_edges)); - GSET_ITER_INDEX (gi, adjacent_edges, i) { - SubdivCCGAdjacentEdge *adjacent_edge = BLI_gsetIterator_getKey(&gi); - adjacent_edge_index_map[i] = adjacent_edge - subdiv_ccg->adjacent_edges; - } - subdiv_ccg_average_boundaries( - subdiv_ccg, key, adjacent_edge_index_map, BLI_gset_len(adjacent_edges)); - - /* Average corners. */ - - adjacent_vertex_index_map = static_or_heap_storage_get(&index_heap, - BLI_gset_len(adjacent_vertices)); - GSET_ITER_INDEX (gi, adjacent_vertices, i) { - SubdivCCGAdjacentVertex *adjacent_vertex = BLI_gsetIterator_getKey(&gi); - adjacent_vertex_index_map[i] = adjacent_vertex - subdiv_ccg->adjacent_vertices; - } - subdiv_ccg_average_corners( - subdiv_ccg, key, adjacent_vertex_index_map, BLI_gset_len(adjacent_vertices)); - - BLI_gset_free(adjacent_vertices, NULL); - BLI_gset_free(adjacent_edges, NULL); - static_or_heap_storage_free(&index_heap); -} - typedef struct StitchFacesInnerGridsData { SubdivCCG *subdiv_ccg; CCGKey *key; |