diff options
author | Hans Goudey <h.goudey@me.com> | 2021-12-10 02:43:30 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-12-10 02:43:30 +0300 |
commit | dffd032bc9b9cd0dbb710f1f3d3f0b14361bc267 (patch) | |
tree | 61dbce4e8189efd6fb3dcaf1e1c3978625c50f65 /source/blender/blenkernel/intern/geometry_set.cc | |
parent | 18412744c8c4231216133f958f74bc38cce54e75 (diff) |
Geometry Nodes: Remove unnecessary copy when replacing data
In the `replace_mesh`/`replace_curve` etc. methods, the component
was retrieved with write access. Retrieving with write access will
duplicate the data if the component has another user. This means that
the replaced geometry data was often duplicated just to be deleted
a moment later.
I expect this would have a large impact in performance in some specific
situations when dealing with large geometry. In a scene with many small
meshes though, I didn't observe a significant difference.
This also makes replacing a geometry set's data with the same data
that's already in the set safe. It would be valid to assert for that
case instead, but this seems safer.
Differential Revision: https://developer.blender.org/D13530
Diffstat (limited to 'source/blender/blenkernel/intern/geometry_set.cc')
-rw-r--r-- | source/blender/blenkernel/intern/geometry_set.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc index 214d88d1a63..7830e897109 100644 --- a/source/blender/blenkernel/intern/geometry_set.cc +++ b/source/blender/blenkernel/intern/geometry_set.cc @@ -353,7 +353,10 @@ void GeometrySet::replace_mesh(Mesh *mesh, GeometryOwnershipType ownership) this->remove<MeshComponent>(); return; } - + if (mesh == this->get_mesh_for_read()) { + return; + } + this->remove<MeshComponent>(); MeshComponent &component = this->get_component_for_write<MeshComponent>(); component.replace(mesh, ownership); } @@ -364,7 +367,10 @@ void GeometrySet::replace_curve(CurveEval *curve, GeometryOwnershipType ownershi this->remove<CurveComponent>(); return; } - + if (curve == this->get_curve_for_read()) { + return; + } + this->remove<CurveComponent>(); CurveComponent &component = this->get_component_for_write<CurveComponent>(); component.replace(curve, ownership); } @@ -375,7 +381,10 @@ void GeometrySet::replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipTy this->remove<PointCloudComponent>(); return; } - + if (pointcloud == this->get_pointcloud_for_read()) { + return; + } + this->remove<PointCloudComponent>(); PointCloudComponent &component = this->get_component_for_write<PointCloudComponent>(); component.replace(pointcloud, ownership); } @@ -386,7 +395,10 @@ void GeometrySet::replace_volume(Volume *volume, GeometryOwnershipType ownership this->remove<VolumeComponent>(); return; } - + if (volume == this->get_volume_for_read()) { + return; + } + this->remove<VolumeComponent>(); VolumeComponent &component = this->get_component_for_write<VolumeComponent>(); component.replace(volume, ownership); } |