Improve handling of embedded data-blocks (root nodetrees and master collections) #69169

Open
opened 2019-08-26 13:25:32 +02:00 by Brecht Van Lommel · 9 comments

Embedded data-blocks often require specific handling in ID management (freeing, duplicating, referencing, RNA paths, etc.).

Characteristics of embedded IDs:

  • They have one and only one owner ID.
    They are flagged as such with LIB_EMBEDDED_DATA. This owner ID takes care of their management (creation, duplication, deletion...).
    ** IDTypeInfo provides a way to get that unique owner ID from an embedded one.
  • They are not stored in Main database.
    However, they can be referenced by other IDs (e.g. master collection of scene can be a parent of many other collections). New embedded IDs are created with LIB_TAG_NO_MAIN, however existing old ones may not have it, and there is no do_version to set it on those...
  • They do have their own animation data.
  • Their name is not unique.
  • They do have a valid session_uuid.
  • They are stored in .blend files as 'regular' data, they do not have the bhead->code set to their ID type.

Proposals for Improvements


Here are ideas to help improve handling of the embedded IDs.

1 - Storing a reference to owner ID in embedded ones

While 'loop-back' ID pointers can be problematic, their support in general ID management code is now fairly safe and sound. This would solve the current issue where we have to loop over all potential owner IDs to find the proper one.

    • Store that id_owner pointer in ID struct itself, or in data of each specific ID type? D15838, cd49fee741
      ** Would rather go for generic pointer in ID struct.

2 - Tags and Library of embedded IDs should match their owner's

Embedded IDs should share the same 'ID management' tags as their owner ID (if owner ID is LIB_TAG_NO_MAIN, its embedded ones are too, etc.). Embedded IDs are not stored in G_MAIN, but are often handled as such, can be referenced by other regular IDs (like master collection being parent of other collections), etc. Similarly, they should also always share the same Library pointer as their owners.

    • Needs to ensure tags are in sync with their owners (need to check exactly which ones need it, document it, and probably add an API to set tags that ensures this behavior). This should wait for #88555/T90610 to be addressed.
    • Needs to ensure lib pointers are always in sync. //Seems to already be the case, 788952705c just adds some extra asserts to double-check that on file read.

3 - Generic 'foreach' looper over embedded pointers only

This could help making some of IDManagement related tasks more generic when dealing with embedded pointers, needs to be investigated further.

There can be two approaches:

  • Add an extra flag option to the existing foreach_id API (aka BKE_lib_query). This imply IDTypeInfo.foreach_id callbacks of types that may own embedded IDs to be aware of this option, to optimize their code by only processing those embedded pointers. Least effort solution, but requires exposing some info from generic foreach_id code into types callbacks. not necessarily a bad thing though.
  • Add a new dedicated callback to IDTypeInfo, that would be somewhat the complement to the existing owner_pointer_get one.

Original task (note that since 2019, we clearly moved towards the second solution described below):

bNodeTree is currently both a datablock, and embedded in materials. Same for collection and master collection of a scene.

This leads to messy datablock management and problems creating RNA paths (e.g. #68971).

A solution to this could be to make bNodeTree node longer a datablock. Instead it would be embedded in Material, World, Light, and a new NodeGroup datablock.
This will require Python API breakage and some relatively complicated versioning, but the resulting design should be cleaner.

Another solution is to design a proper handling of those private data-blocks all around our code base (ID/Lib management in BKE_library area, RNA handling of IDs, etc.). We already do that to some point, but so far it has mostly been hacks around issues on a case-by-case basis.
Solution to #68971 already added a new ID flag to mark those private datablocks, e.g. we could extend RNA handling of IDs to detect that one and automatically consider those structs as the other private sub-data ones (like e.g. render settings from scene, etc.).

Embedded data-blocks often require specific handling in ID management (freeing, duplicating, referencing, RNA paths, etc.). Characteristics of embedded IDs: * They have one and only one owner ID. **They are flagged as such with `LIB_EMBEDDED_DATA`.** This owner ID takes care of their management (creation, duplication, deletion...). ** IDTypeInfo provides a way to get that unique owner ID from an embedded one. * They are not stored in Main database. **However, they can be referenced by other IDs *(e.g. master collection of scene can be a parent of many other collections)*.** New embedded IDs are created with `LIB_TAG_NO_MAIN`, however existing old ones may not have it, and there is no `do_version` to set it on those... * They do have their own animation data. * Their name is not unique. * They do have a valid `session_uuid`. * They are stored in .blend files as 'regular' data, they do not have the `bhead->code` set to their ID type. Proposals for Improvements **** Here are ideas to help improve handling of the embedded IDs. 1 - Storing a reference to owner ID in embedded ones ---------------------------------------------------------------- While 'loop-back' ID pointers can be problematic, their support in general ID management code is now fairly safe and sound. This would solve the current issue where we have to loop over all potential owner IDs to find the proper one. * - [x] Store that `id_owner` pointer in `ID` struct itself, or in data of each specific ID type? [D15838](https://archive.blender.org/developer/D15838), cd49fee741 ** *~~Would rather go for generic pointer in `ID` struct.~~* 2 - Tags and Library of embedded IDs should match their owner's ----------------------------------------------------------------------------- Embedded IDs should share the same 'ID management' tags as their owner ID (if owner ID is `LIB_TAG_NO_MAIN`, its embedded ones are too, etc.). Embedded IDs are not stored in `G_MAIN`, but are often handled as such, can be referenced by other regular IDs (like master collection being parent of other collections), etc. Similarly, they should also always share the same Library pointer as their owners. * - [ ] Needs to ensure tags are in sync with their owners (need to check exactly which ones need it, document it, and probably add an API to set tags that ensures this behavior). *This should wait for #88555/T90610 to be addressed.* * - [x] Needs to ensure lib pointers are always in sync. //Seems to already be the case, 788952705c just adds some extra asserts to double-check that on file read. 3 - Generic 'foreach' looper over embedded pointers only ------------------------------------------------------------------- This could help making some of IDManagement related tasks more generic when dealing with embedded pointers, needs to be investigated further. There can be two approaches: - Add an extra flag option to the existing `foreach_id` API (aka `BKE_lib_query`). This imply `IDTypeInfo.foreach_id` callbacks of types that may own embedded IDs to be aware of this option, to optimize their code by only processing those embedded pointers. *Least effort solution, but requires exposing some info from generic foreach_id code into types callbacks. not necessarily a bad thing though.* - Add a new dedicated callback to `IDTypeInfo`, that would be somewhat the complement to the existing `owner_pointer_get` one. ----------------------- *Original task (note that since 2019, we clearly moved towards the second solution described below):* `bNodeTree` is currently both a datablock, and embedded in materials. Same for collection and master collection of a scene. This leads to messy datablock management and problems creating RNA paths (e.g. #68971). A solution to this could be to make `bNodeTree` node longer a datablock. Instead it would be embedded in `Material`, `World`, `Light`, and a new `NodeGroup` datablock. This will require Python API breakage and some relatively complicated versioning, but the resulting design should be cleaner. Another solution is to design a proper handling of those private data-blocks all around our code base (ID/Lib management in BKE_library area, RNA handling of IDs, etc.). We already do that to some point, but so far it has mostly been hacks around issues on a case-by-case basis. Solution to #68971 already added a new ID flag to mark those private datablocks, e.g. we could extend RNA handling of IDs to detect that one and automatically consider those structs as the other private sub-data ones (like e.g. render settings from scene, etc.).
Author
Owner

Added subscriber: @brecht

Added subscriber: @brecht

#86119 was marked as duplicate of this issue

#86119 was marked as duplicate of this issue
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3
Bastien Montagne changed title from Improve embedded nodetree storage to Improve embedded nodetree/master collection storage & handling 2019-08-29 15:51:25 +02:00

Added subscriber: @Pipeliner

Added subscriber: @Pipeliner

Added subscriber: @BartekMoniewski

Added subscriber: @BartekMoniewski
Member

Added subscriber: @Imaginer

Added subscriber: @Imaginer
Bastien Montagne changed title from Improve embedded nodetree/master collection storage & handling to Improve handling of embedded data-blocks (root nodetrees and master collections) 2021-02-25 11:38:31 +01:00

Added subscriber: @mont29

Added subscriber: @mont29
Author
Owner

This seems generally fine.

I'd personally try to save memory and put id_owner in specific datablocks that are embedded, but not a big deal either way.

This seems generally fine. I'd personally try to save memory and put `id_owner` in specific datablocks that are embedded, but not a big deal either way.
Philipp Oeser removed the
Interest
Animation & Rigging
label 2023-02-09 14:36:38 +01:00
Sign in to join this conversation.
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
8 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#69169
No description provided.