This commit rewrites the PBVH drawing using many of the principles from the ongoing sculpt refactor. First of all, per BVH node overhead is minimized. Previously the main entry point to the drawing API was per node, so there was significant overhead fetching global data and maintaining caches on a per-node basis. Now all of that "global" work happens for the entire geometry. We also now avoid creating wireframe index buffers and batches unless the viewport actually requests wireframe data. This was theoretically possible before, but the whole logic flow was so convoluted that the optimization was too difficult. Similarly, multithreading is used more consistently now. Because of OpenGL, flushing vertex/index buffers to the GPU has to happen on the main thread, but everything else can be multithreaded. With outer loops processing all relevant PBVH nodes, it's now trivial to apply multithreading wherever possible. Testing performance, overall this commit results in a 10% improvement in the time between opening a file with a large mesh sculpt and the first possible interaction. Specifically I measured a change from 8.4 to 7.6 seconds on a completely visible 16 million vertex mesh with a Ryzen 7950x. I also measured a decrease in memory usage from 4.79 to 4.31 GB. For multires I observed a similar improvement in memory usage, though less of a performance improvement. There are still significant opportunities for future improvement. #122775 would be particularly helpful. #99983 would be helpful too, though more complicated, and #97665 describes the problems a bit more generally. Part of #118145. Pull Request: https://projects.blender.org/blender/blender/pulls/127002
72 lines
2.5 KiB
C++
72 lines
2.5 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BKE_pbvh.hh"
|
|
|
|
/** \file
|
|
* \ingroup bke
|
|
*/
|
|
|
|
/* pbvh.cc */
|
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
bool ray_face_intersection_quad(const float3 &ray_start,
|
|
IsectRayPrecalc *isect_precalc,
|
|
const float3 &t0,
|
|
const float3 &t1,
|
|
const float3 &t2,
|
|
const float3 &t3,
|
|
float *depth);
|
|
bool ray_face_intersection_tri(const float3 &ray_start,
|
|
IsectRayPrecalc *isect_precalc,
|
|
const float3 &t0,
|
|
const float3 &t1,
|
|
const float3 &t2,
|
|
float *depth);
|
|
|
|
bool ray_face_nearest_quad(const float3 &ray_start,
|
|
const float3 &ray_normal,
|
|
const float3 &t0,
|
|
const float3 &t1,
|
|
const float3 &t2,
|
|
const float3 &t3,
|
|
float *r_depth,
|
|
float *r_dist_sq);
|
|
bool ray_face_nearest_tri(const float3 &ray_start,
|
|
const float3 &ray_normal,
|
|
const float3 &t0,
|
|
const float3 &t1,
|
|
const float3 &t2,
|
|
float *r_depth,
|
|
float *r_dist_sq);
|
|
|
|
/* pbvh_bmesh.cc */
|
|
|
|
bool bmesh_node_raycast(blender::bke::pbvh::BMeshNode &node,
|
|
const float3 &ray_start,
|
|
const float3 &ray_normal,
|
|
IsectRayPrecalc *isect_precalc,
|
|
float *dist,
|
|
bool use_original,
|
|
PBVHVertRef *r_active_vertex,
|
|
float *r_face_normal);
|
|
bool bmesh_node_nearest_to_ray(blender::bke::pbvh::BMeshNode &node,
|
|
const float3 &ray_start,
|
|
const float3 &ray_normal,
|
|
float *depth,
|
|
float *dist_sq,
|
|
bool use_original);
|
|
|
|
void bmesh_normals_update(Tree &pbvh, const IndexMask &nodes_to_update);
|
|
|
|
/* pbvh_pixels.hh */
|
|
|
|
void node_pixels_free(blender::bke::pbvh::Node *node);
|
|
void pixels_free(blender::bke::pbvh::Tree *pbvh);
|
|
|
|
} // namespace blender::bke::pbvh
|