Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pbvh.c
| Show First 20 Lines • Show All 1,090 Lines • ▼ Show 20 Lines | static void pbvh_faces_update_normals(PBVH *bvh, PBVHNode **nodes, int totnode) | ||||
| */ | */ | ||||
| PBVHUpdateData data = { | PBVHUpdateData data = { | ||||
| .bvh = bvh, | .bvh = bvh, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .vnors = vnors, | .vnors = vnors, | ||||
| }; | }; | ||||
| TaskParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_accum_task_cb, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_normals_accum_task_cb, &settings); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_normals_store_task_cb, &settings); | |||||
| BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_store_task_cb, &settings); | |||||
| MEM_freeN(vnors); | MEM_freeN(vnors); | ||||
| } | } | ||||
| static void pbvh_update_mask_redraw_task_cb(void *__restrict userdata, | static void pbvh_update_mask_redraw_task_cb(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict UNUSED(tls)) | const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| Show All 33 Lines | |||||
| static void pbvh_update_mask_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag) | static void pbvh_update_mask_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag) | ||||
| { | { | ||||
| PBVHUpdateData data = { | PBVHUpdateData data = { | ||||
| .bvh = bvh, | .bvh = bvh, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .flag = flag, | .flag = flag, | ||||
| }; | }; | ||||
| TaskParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BLI_task_parallel_range(0, totnode, &data, pbvh_update_mask_redraw_task_cb, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_mask_redraw_task_cb, &settings); | ||||
| } | } | ||||
| static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata, | static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict UNUSED(tls)) | const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| PBVHUpdateData *data = userdata; | PBVHUpdateData *data = userdata; | ||||
| PBVH *bvh = data->bvh; | PBVH *bvh = data->bvh; | ||||
| Show All 19 Lines | |||||
| { | { | ||||
| /* update BB, redraw flag */ | /* update BB, redraw flag */ | ||||
| PBVHUpdateData data = { | PBVHUpdateData data = { | ||||
| .bvh = bvh, | .bvh = bvh, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .flag = flag, | .flag = flag, | ||||
| }; | }; | ||||
| TaskParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BLI_task_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); | ||||
| } | } | ||||
| static int pbvh_get_buffers_update_flags(PBVH *bvh, bool show_vcol) | static int pbvh_get_buffers_update_flags(PBVH *bvh, bool show_vcol) | ||||
| { | { | ||||
| int update_flags = 0; | int update_flags = 0; | ||||
| update_flags |= bvh->show_mask ? GPU_PBVH_BUFFERS_SHOW_MASK : 0; | update_flags |= bvh->show_mask ? GPU_PBVH_BUFFERS_SHOW_MASK : 0; | ||||
| update_flags |= show_vcol ? GPU_PBVH_BUFFERS_SHOW_VCOL : 0; | update_flags |= show_vcol ? GPU_PBVH_BUFFERS_SHOW_VCOL : 0; | ||||
| return update_flags; | return update_flags; | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | static void pbvh_update_draw_buffers( | ||||
| /* Parallel creation and update of draw buffers. */ | /* Parallel creation and update of draw buffers. */ | ||||
| PBVHUpdateData data = { | PBVHUpdateData data = { | ||||
| .bvh = bvh, | .bvh = bvh, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .show_vcol = show_vcol, | .show_vcol = show_vcol, | ||||
| }; | }; | ||||
| TaskParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BLI_task_parallel_range(0, totnode, &data, pbvh_update_draw_buffer_cb, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_draw_buffer_cb, &settings); | ||||
| } | } | ||||
| static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag) | static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag) | ||||
| { | { | ||||
| int update = 0; | int update = 0; | ||||
| /* difficult to multithread well, we just do single threaded recursive */ | /* difficult to multithread well, we just do single threaded recursive */ | ||||
| if (node->flag & PBVH_Leaf) { | if (node->flag & PBVH_Leaf) { | ||||
| ▲ Show 20 Lines • Show All 1,424 Lines • ▼ Show 20 Lines | bool pbvh_has_mask(PBVH *bvh) | ||||
| return false; | return false; | ||||
| } | } | ||||
| void pbvh_show_mask_set(PBVH *bvh, bool show_mask) | void pbvh_show_mask_set(PBVH *bvh, bool show_mask) | ||||
| { | { | ||||
| bvh->show_mask = show_mask; | bvh->show_mask = show_mask; | ||||
| } | } | ||||
| void BKE_pbvh_parallel_range_settings(TaskParallelSettings *settings, | void BKE_pbvh_parallel_range_settings(PBVHParallelSettings *settings, | ||||
| bool use_threading, | bool use_threading, | ||||
| int totnode) | int totnode) | ||||
| { | { | ||||
| const int threaded_limit = 1; | memset(settings, 0, sizeof(*settings)); | ||||
| BLI_parallel_range_settings_defaults(settings); | settings->use_threading = use_threading && totnode > 1; | ||||
| settings->use_threading = use_threading && (totnode > threaded_limit); | |||||
| settings->min_iter_per_thread = 1; | |||||
| settings->scheduling_mode = TASK_SCHEDULING_DYNAMIC; | |||||
| } | } | ||||