Custom Data: support implicit sharing for custom data layers #106228
Merged
Jacques Lucke
merged 34 commits from 2023-04-13 14:58:08 +02:00
JacquesLucke/blender:implicit-sharing-custom-data
into main
Reviewers
Request review
No reviewers
Labels
Clear labels
This issue affects/is about backward or forward compatibility
Issues relating to security: https://wiki.blender.org/wiki/Process/Vulnerability_Reports
Apply labels
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
This issue affects/is about backward or forward compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
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
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
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
Issues relating to security: https://wiki.blender.org/wiki/Process/Vulnerability_Reports
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 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 & 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
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
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
Milestone
Set milestone
Clear milestone
No items
No Milestone
Projects
Set Project
Clear projects
No project
Assignees
Assign users
Clear assignees
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#106228
Reference in New Issue
There is no content yet.
Delete Branch "JacquesLucke/blender:implicit-sharing-custom-data"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
This integrates the new implicit-sharing system (from
fbcddfcd68
) withCustomData
. Now the potentially long arrays referenced by custom data layers can be shared between different systems but most importantly between different geometries. This makes e.g. copying a mesh much cheaper because none of the attributes has to be copied. Only when an attribute is modified does it have to be copied.Also see the original design task: #95845.
This reduces memory and improves performance by avoiding unnecessary data copies. For example, the used memory after loading a highly subdivided mesh is reduced from 2.4GB to 1.79GB. This is about 25% less which is the expected amount because in
main
there are 4 copies of the data:This patch only gets rid of copy number 2 for the depsgraph. In theory the other copies can be removed as part of follow up PRs as well though.
The patch has three main components:
CustomData
API to make it work better with implicit sharing:CD_REFERENCE
andCD_DUPLICATE
have been removed because they are meaningless when implicit-sharing is used.CD_ASSIGN
has been removed as well because it's not an allocation type anyway. The functionality of using existing arrays as custom data layers has not been removed though.CustomData_add_layer_with_data
which also has a new argument that allows passing in information about whether the array is shared.CD_FLAG_NOFREE
has been removed because it's no longer necessary. It only existed because ofCD_REFERENCE
.CustomData_copy
andCustomData_merge
have been split up into a functions that do copy the actual attribute values and those that do not. The latter functions now have the_layout
suffix (e.g.CustomData_copy_layout
).customdata.cc
to make it actually use implicit-sharing.BKE_customdata.h
.@blender-bot build
@blender-bot build
WIP: Custom Data: support implicit sharing for custom data layersto Custom Data: support implicit sharing for custom data layersA very nice improvement in the custom data API and more obviously in memory usage! This all looks nice to me. I just added a few inline comments.
I think this actually will improve memory usage in sculpt undo system when full copies are made, since
SCULPT_UNDO_GEOMETRY
is implemented basically just withCustomData_copy
. It's nice when just changing the API slightly will give that improvement.To get used to this I'll probably try to implement it implicit sharing for mesh and curve offsets next, if that makes sense to you.
@ -163,1 +156,3 @@
* if a layer should be copied or not. alloctype must be one of the above.
* Initializes a CustomData object with the same layer setup as source. `mask` is a bit-field where
* `(mask & (1 << (layer type)))` indicates if a layer should be copied or not. The data layers
* will be shared or copied depending on whether the layer uses COW.
What does "whether the layer uses COW" mean? Aren't all layers potentially shared?
@ -233,2 +242,2 @@
* backed by an external data array. the different allocation types are
* defined above. returns the data of the layer.
* Adds a layer of the given type to the #CustomData object. The new layer is initialized based on
* the given alloctype. \return The layer data.
Missing newline before
\return
@ -2314,0 +2376,4 @@
};
/** Create a #ImplicitSharingInfo that takes ownership of the data. */
static ImplicitSharingInfo *make_cow_for_array(const eCustomDataType type,
Is it purposeful to still reference
cow
here? I'm not opposed to it, just pointing it out in case it wasn't.@ -2732,3 +2840,3 @@
}
static bool customData_resize(CustomData *data, const int amount)
static void customData_resize(CustomData *data, const int grow_amount)
This change to
customData_resize
is logically totally separate from the rest of the patch I think. Maybe it could be committed separately? Much nicer though :)Same with the change to
typeInfo
below TBH.@ -626,3 +626,3 @@
CustomData_free(&pointcloud->pdata, pointcloud->totpoint);
pointcloud->totpoint = me->totvert;
CustomData_merge(&me->vdata, &pointcloud->pdata, CD_MASK_PROP_ALL, CD_DUPLICATE, me->totvert);
No need for a newline here IMO
@ -274,2 +275,4 @@
if (layer->data) {
if (layer->sharing_info) {
/* This assumes that the layer is not shared, which it is not here because it has just
IIRC the old patch had a comment about this in the description. Though it's not really ugly anymore, it's nice if this becomes a bit actionable, like "this could be improved by...", and that sort of comment might fit in the PR (or here I guess).
@blender-bot build
@blender-bot build windows
@blender-bot build
Great memory optimization! I also like how the CustomData functions are documented and have more clear naming :)
Took me a bit to understand what the
BLI_implicit_sharing.h
is about. Maybe add a comment that it is for forward declaration a class defined in theBLI_implicit_sharing.hh
but which is available for both C and C++? Just a thought.From the code side seems good. Did you test it with some complex files like from some of the open movies (like, the current one)? Do you want us to do some testing here at the studio?
I did open a few Heist files, changed some small things, and hit undo. That worked as expected. I don't yet have access to the current open movie. Any additional testing at the studio would be appreciated!
@blender-bot package
Package build started. Download here when ready.
Gave it a test with the production file I've been looking into recently. So far so good!
I'm mainly waiting for final approval by @brecht now.
@ -240,0 +250,4 @@
/**
* Adds a layer of the given type to the #CustomData object. The new layer takes ownership of the
* passed in `layer_data`. If a #ImplicitSharingInfoHandle is passed in, it's user count is
it's -> its
Reviewers