Core: new blenlib library for implicit-sharing #105994
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105994
Loading…
Reference in New Issue
No description provided.
Delete Branch "JacquesLucke/blender:implicit-sharing"
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?
This was originally part of #104478, but has been split out for easier review.
The overall goal is to use implicit-sharing in many places in Blender that currently do unnecessary copies. See #95845 for more details.
This commit only adds the base data structures in blenlib and uses those in
GeometrySet
andAnonymousAttributeID
, which used a more ad-hoc version of implicit sharing already.The plan is to follow this up with implicit-sharing integrations in places in Blender:
CustomData
: Allows sharing attributes between multiple data blocks, significantly reducing the cost of copying a geometry data-block.Attribute
: Avoids copying attributes into cycles for rendering.GPUVertBuf
; Avoids copying attributes for viewport/eevee rendering.This looks good to me. I added some comments inline but they're more like questions so I'll accept this now. The naming seems fine to me, though I don't think
Implicit
is adding much besides making the name a bit longer and more unique.Do you think it would be reasonable for
ImplicitSharingPtr
to have a function likemake_mutable()
, essentially to handle the "copy" part of copy-on-write.That would be useful for
get_component_for_write
and potentially when eagerly updating mesh caches (if they were usingImplicitSharingPtr
instead ofshared_ptr
. It would also have to know how to copy the data, so maybe it's fine to do that on another level, I'm just curious honestly.@ -0,0 +52,4 @@
bool is_shared() const
{
return users_.load(std::memory_order_relaxed) >= 2;
}
This could be over-documenting and redundant, I wonder what you think, but possibly some comments like this could help people answer their questions faster:
/** True if there are other const references to the resource, meaning it cannot be modified. */
/** Whether the resource can be modified without a copy. */
/** Call when creating another const reference/pointer to the data. */
etc.
@ -0,0 +80,4 @@
};
/**
* Makes it easy to embed implicit-sharing behavior into a struct. This also allows the subclass to
This comment is a bit hard to follow, maybe replacing
the subclass
with something more specific would help (like saying the ptr class can be used with a class that derives from the mixin class).@ -0,0 +13,4 @@
/**
* #ImplicitSharingPtr is a smart pointer that manages implicit sharing. It's designed to work with
* types that derive from #ImplicitSharingMixin. It is fairly similar to #std::shared_ptr but
* expects the reference count to be embedded in the data.
expects
->requires
, right?std::make_shared
will allocate the use count with the object so it's helpful to clarify this a bit.The reason for using
Implicit
is that this is a standard name for what we are doing here, think that's good. I don't care much about the slightly longer name here. In practice that name should show up in code super often, since its use is implicit ;DCurrently, I think no, because then the
ImplicitSharingInfo
would also have to know how to copy the data. It's possible that different users want to copy the data in different ways though (e.g. copy an attribute into a buffer allocated by another allocator, not that we need that now, but it's a possibility). Besides that, I think especially for attributes it probably often makes sense to just replace an attribute buffer instead of copying and then modifying it.@blender-bot build
@ -0,0 +73,4 @@
*/
void remove_user_and_delete_if_last() const
{
const int old_user_count = users_.fetch_sub(1, std::memory_order_relaxed);
My understanding is that user count decrement requires
std::memory_order_acq_rel
, while increment can usestd::memory_order_relaxed
.For example libc++ does this for shared_ptr. More details:
https://stackoverflow.com/questions/48124031/stdmemory-order-relaxed-atomicity-with-respect-to-the-same-atomic-variable
Would be nice to have the BLI types tested. Even if currently the tests might look trivial, it does help in the future nevertheless.
Since it is not really a new library, but more like a refactor of existing code is probably fine to move forward with this patch.
@blender-bot build
Jacques Lucke referenced this pull request2023-03-28 17:02:32 +02:00