Cleanup: Use Vector for passing lists of PBVHNodes around #106884
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#106884
Loading…
Reference in New Issue
No description provided.
Delete Branch "temp-sculpt-vector-nodes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cleaned up sculpt code to store lists of
PBVHNodes
withblender::Vector
instead of simple pointer arrays. This is muchsimpler and eliminates memory leaks caused by forgetting to free
the result of
BKE_pbvh_search_gather
.Notes:
BKE_pbvh_search_gather
is nowblender::pbvh::search_gather
.FilterCache
andExpandCache
have ownership over their .nodesmembers; as a result they're no longer pure C structs and
are allocated with
MEM_new
/MEM_delete
.source/blender/editors/sculpt_paint
Todo (not for this PR): create a new properly C++ task API for sculpt
(with lambdas) and use it for brushes.
Generally I really like the change. It definitely moves the code to a much better state.
There are couple of suggestion points.
@ -837,0 +830,4 @@
namespace blender::pbvh {
Vector<PBVHNode *> search_gather(PBVH *pbvh, BKE_pbvh_SearchCallback scb, void *search_data);
Vector<PBVHNode *> search_gather_ex(PBVH *pbvh,
To me it would be more readable to either have polymorphic
search_gather ()
or a singlesearch_gather()
with thePBVHNodeFlags leaf_flag = PBVH_Leaf
.@ -1660,3 +1663,3 @@
}
void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
void pbvh_bmesh_normals_update(Vector<PBVHNode *> &nodes)
For such things I find it much more reliable and flexible to use span. I think in BLI terminology it will be
MutableSpan<PBVHNode *> nodes
.It decouples from the specific of the actual storage used, solves possible issues if one forgets to add
&
, and allows easier use for things like callback data (re)assignment.And for cases where vector is to be passes and is not modified, use
const
qualifier.Me and Hans settled on using Span.
@blender-bot build
Do you plan more changes w.r.t Span?
Seems that
PBVHUpdateData
,pbvh_faces_update_normals
,pbvh_update_draw_buffers
and others can use it. Is just quickly checking forVector<PBVHNode *> &
to see where it is still used.A great improvement! I found some smaller things inline though.
@ -835,2 +828,4 @@
#ifdef __cplusplus
}
namespace blender::pbvh {
We're in blenkernel here, so the full namespace should be
blender::bke::pbvh
@ -1411,3 +1369,2 @@
PBVH *pbvh;
PBVHNode **nodes;
int totnode;
Vector<PBVHNode *> &nodes;
Span<PBVHNode *> nodes
here too I think. Not using a reference avoids the need to add the constructor there too@ -1521,3 +1480,3 @@
}
static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode)
static void pbvh_faces_update_normals(PBVH *pbvh, Vector<PBVHNode *> &nodes)
Vector<PBVHNode *> &
->Span<PBVHNode *>
@ -1583,3 +1542,3 @@
}
static void pbvh_update_mask_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, int flag)
static void pbvh_update_mask_redraw(PBVH *pbvh, Vector<PBVHNode *> &nodes, int flag)
Vector<PBVHNode *> &
->Span<PBVHNode *>
@ -1619,3 +1578,3 @@
}
static void pbvh_update_visibility_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, int flag)
static void pbvh_update_visibility_redraw(PBVH *pbvh, Vector<PBVHNode *> &nodes, int flag)
Vector<PBVHNode *> &
->Span<PBVHNode *>
I won't bother commenting that anymore, it's the same elsewhere.
@ -3193,3 +3122,2 @@
/* Update draw buffers. */
if (totnode != 0 && (update_flag & (PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers))) {
pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag);
if (nodes.size() != 0 && (update_flag & (PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers))) {
nodes.size() != 0
->!nodes.is_empty()
Might as well do this here
@ -544,3 +543,2 @@
MEM_SAFE_FREE(sgcontext->operation);
MEM_SAFE_FREE(sgcontext->nodes);
MEM_SAFE_FREE(sgcontext);
MEM_delete<SculptGestureContext>(sgcontext);
Writing
<SculptGestureContext>
should be unnecessary forMEM_delete
, since the pointer already has that type.Thanks, I tend to have an irrational fear of template argument deduction.
@ -624,1 +617,3 @@
&sgcontext->totnode);
sgcontext->nodes = blender::pbvh::search_gather(
ss->pbvh, BKE_pbvh_node_frustum_contain_AABB, &frustum)
.as_span();
.as_span()
is forcing a copy here. Without it,SculptGestureContext
would be able to take ownership of the vector returned bysearch_gather
. Same above.@ -3429,2 +3422,2 @@
sizeof(*accum) * totnode, __func__);
blender::threading::parallel_for(IndexRange(totnode), 1LL, [&](IndexRange range) {
sizeof(*accum) * nodes.size(), __func__);
blender::threading::parallel_for(IndexRange(nodes.size()), 1LL, [&](IndexRange range) {
IndexRange(nodes.size())
->nodes.index_range()
@ -6151,2 +6095,3 @@
nodes = blender::pbvh::search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data);
if (totnode == 0) {
if (nodes.size() == 0) {
nodes.size() == 0
->nodes.is_empty()
@ -86,3 +87,3 @@
data.ignore_fully_ineffective = false;
data.center = ss->cache->initial_location;
BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
nodes = blender::pbvh::search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data);
Maybe just return the nodes directly here, rather than assigning them to a variable and returning the variable after the switch
@ -89,2 +86,3 @@
Vector<PBVHNode *> nodes = blender::pbvh::search_gather(ss->pbvh, nullptr, nullptr);
if (!totnodes) {
if (!nodes.size()) {
!nodes.size()
->nodes.is_empty()
Same elsewhere in this diff
Accepting now, there are a few tiny things to clean up inline though.
@ -1655,3 +1615,3 @@
}
void pbvh_update_BB_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, int flag)
void pbvh_update_BB_redraw(PBVH *pbvh, Span<PBVHNode *> nodes, int flag)
@ -3957,2 +3913,3 @@
Vector<PBVHNode *> nodes = blender::bke::pbvh::gather_proxies(ss->pbvh);
threading::parallel_for(IndexRange(totnode), 1, [&](IndexRange range) {
threading::parallel_for(IndexRange(nodes.size()), 1, [&](IndexRange range) {
IndexRange(nodes.size())
->nodes.index_range()
Three of these in this file.
@ -13,6 +13,7 @@
#include "BLI_math.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BLI_span.hh"
make format
@ -273,2 +272,2 @@
BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode);
BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings);
BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->nodes.size());
BLI_task_parallel_range(0, ss->filter_cache->nodes.size(), &data, sculpt_expand_task_cb, &settings);
make format