Port operators to use COW (Parent Task) #54810

Closed
opened 2018-04-25 13:13:16 +02:00 by Joshua Leung · 16 comments
Member

This is the parent task for the copy-on-write operator porting taskforce.

With copy-on-write in place we have clear separation between original data and evaluated state: dependency graph gets original data, goes through all the animation systems, drivers, constraints and modifiers stack and gets evaluated state of that data within the current context.
This means that now operators should read from an evaluated state and write to original data, and to inform dependency graph about changes.
Practical example: if an operator needs to get an object matrix, it should read it from the evaluated version. But if the operator needs to update the object’s location, it should write it to the original object and tag it as updated.

For further information read the dependency graph design .

How this works:

  1. Find an operator you want to port in the linked sub-tasks below.
  2. Submit patches for review using arcanist - tagging @Sergey and @JoshuaLeung as reviewers.
  3. Once the patch is reviewed and committed, the operator in the task will be marked as "done".

Note: Not all operators will actually need fixing (many should be fine already, without needing further changes). In that case, instead of submitting a patch, mark the operator as done directly.

What to do:

The code work is straightforward. But there are things which will help migrating operators:

  • To go from original object to evaluated, use DEG_get_evaluated_object().
To go from original ID to evaluated use `DEG_get_evaluated_id()`.
 Keep in mind, these functions do hash lookup based on ID, so if multiple lookups of same object is needed try to store result of this lookup.
  • To go from evaluated to original object use DEG_get_original_object().
 To go from evaluated to original ID use `DEG_get_original_id()`.
 These functions are cheap.
  • There is also a DEG_get_evaluated_rna_pointer() method that can be used in exceptional cases. Unlike the other functions, it is slow - other methods should be used where possible.
  • If some operator changes interface-only data (example: scene’s 3d cursor location) apart form notifier also use DEG_id_tag_update(id, DEG_TAG_COPY_ON_WRITE); (e.g., 6a75a1a669).

Other examples:

  • 40199c1d10 - Manipulator: Use evaluated object's matrix to get manipulator position.
  • eb521b22b2 - Make View Selected to be aware of copy-on-write.
  • 3e26b84397 - Camera manipulator: Make it aware of evaluated version of object.

Testing:

Run Blender normally.

  • If the operator works as well as it did in 2.7, it works!
  • If there are problems (e.g. things won't update, invalid results, etc.) the operator (still) needs some more fixes applied.

We also found the following tips useful:

  • Add the --debug-depsgraph-tag to check if the correct tagging updates are happening
  • Use the --disable-copy-on-write flag to check if something else in 2.8 (e.g. Message Bus system) may be causing refresh issues
  • Try checking what happens when using the operators in an animated setup. Some tools only break during animation
  • Sometimes other object data properties may be broken/requiring updates (e.g. armature settings, constraint influence, or shape keys).

Design Notes:

  1. Context (bContext) contains original non-evaluated data. This means CTX_data_scene will give original scene, not evaluated.
  This is also valid for context in Python.
  1. Main structure is always holding original datablocks.
  2. Naming is very important to keep things clear. Agreed convention is: for evaluated versions of data we add _eval suffix to variables.
  3. Where possible, mark evaluated data variables as const

Sub-tasks for each module's operators:

Stuff you can do now:

Major Changes Required (High Priority - for Blender Studio Migration to 2.8):

Major Changes Required (Lower Priority):

Likely Only Minor Changes Needed:

Postponed (Blocking/Pending Issues need resolving first)

Waiting for Sergey to test/check first

  • Curve/Surface (CURVE_OT_*)
  • Font (FONT_OT_*)
  • Metaballs (META_OT_*)
  • Lattices (LATTICE_OT_*)

Waiting for Grease Pencil branch merge

Grease Pencil module (editors/gpencil)

Should be fine without needing fixes

  • Console
  • View2D
  • Text Editor

May need fixes at some point (but aren't operators/for taskforce work)

  • editors/space_view3d/view3d_manipulator_*.c
This is the parent task for the **copy-on-write operator** porting taskforce. With copy-on-write in place we have clear separation between original data and evaluated state: dependency graph gets original data, goes through all the animation systems, drivers, constraints and modifiers stack and gets evaluated state of that data within the current context. This means that now operators should read from an evaluated state and write to original data, and to inform dependency graph about changes. Practical example: if an operator needs to get an object matrix, it should read it from the evaluated version. But if the operator needs to update the object’s location, it should write it to the original object and tag it as updated. For further information read the [dependency graph design ](https://wiki.blender.org/wiki/Source/Depsgraph). # How this works: 1) Find an operator you want to port in the linked sub-tasks below. 2) Submit patches for review using [arcanist ](https://wiki.blender.org/wiki/Tools/CodeReview#Use_Arcanist) - tagging @Sergey and @JoshuaLeung as reviewers. 3) Once the patch is reviewed and committed, the operator in the task will be marked as "done". **Note**: Not all operators will actually need fixing (many should be fine already, without needing further changes). In that case, instead of submitting a patch, mark the operator as done directly. ## What to do: The code work is straightforward. But there are things which will help migrating operators: * To go from original object to evaluated, use `DEG_get_evaluated_object()`. ``` To go from original ID to evaluated use `DEG_get_evaluated_id()`. Keep in mind, these functions do hash lookup based on ID, so if multiple lookups of same object is needed try to store result of this lookup. ``` * To go from evaluated to original object use `DEG_get_original_object()`. ``` To go from evaluated to original ID use `DEG_get_original_id()`. These functions are cheap. ``` * There is also a `DEG_get_evaluated_rna_pointer()` method that can be used in exceptional cases. Unlike the other functions, it is slow - other methods should be used where possible. * If some operator changes interface-only data (example: scene’s 3d cursor location) apart form notifier also use `DEG_id_tag_update(id, DEG_TAG_COPY_ON_WRITE);` (e.g., 6a75a1a669). Other examples: * 40199c1d10 - Manipulator: Use evaluated object's matrix to get manipulator position. * eb521b22b2 - Make View Selected to be aware of copy-on-write. * 3e26b84397 - Camera manipulator: Make it aware of evaluated version of object. ## Testing: Run Blender normally. * If the operator works as well as it did in 2.7, it works! * If there are problems (e.g. things won't update, invalid results, etc.) the operator (still) needs some more fixes applied. We also found the following tips useful: * Add the `--debug-depsgraph-tag` to check if the correct tagging updates are happening * Use the `--disable-copy-on-write` flag to check if something else in 2.8 (e.g. Message Bus system) may be causing refresh issues * Try checking what happens when using the operators in an animated setup. Some tools only break during animation * Sometimes other object data properties may be broken/requiring updates (e.g. armature settings, constraint influence, or shape keys). ## Design Notes: 1) Context (`bContext`) contains original non-evaluated data. This means `CTX_data_scene` will give original scene, not evaluated. ``` This is also valid for context in Python. ``` 2) Main structure is always holding original datablocks. 3) Naming is very important to keep things clear. Agreed convention is: for evaluated versions of data we add `_eval` suffix to variables. 4) Where possible, mark evaluated data variables as `const` # Sub-tasks for each module's operators: ## Stuff you can do now: **Major Changes Required (High Priority - for Blender Studio Migration to 2.8):** - View3D - #54829 - Transform - #54831 - Object - #54817 - ~~Pose Tools~~ - #54812 - Physics - #54818 - Sculpt - #54821 - Render - #54819 - ~~Animation Editors/Module~~ - [**Required changes here are being tackled by @JoshuaLeung** Some things are broken (e.g. recalc after editing keyframes)] **Major Changes Required (Lower Priority):** - ~~Armature Edit Mode~~ - #54811 - IO - #54813 - Mask - #54814 - Paint - #54820 - Sound - #54822 - Movie Clip Editor - #54823 - Image Editor - #54824 - UV Editor - #54830 **Likely Only Minor Changes Needed:** - User Interface Stuff - #54832 - Mesh - ~~#54815~~ (all but blend_from_shape) - Node Editor - #54825 - Outliner - #54827 - Sequencer - #54828 ## Postponed (Blocking/Pending Issues need resolving first) **Waiting for Sergey to test/check first** - Curve/Surface (`CURVE_OT_*`) - Font (`FONT_OT_*`) - Metaballs (`META_OT_*`) - Lattices (`LATTICE_OT_*`) **Waiting for Grease Pencil branch merge** Grease Pencil module (`editors/gpencil`) * COW Task - #55392 * GP Branch Merge Task - #54893 **Should be fine without needing fixes** - Console - View2D - Text Editor **May need fixes at some point (but aren't operators/for taskforce work)** - `editors/space_view3d/view3d_manipulator_*.c`
Joshua Leung self-assigned this 2018-04-25 13:13:16 +02:00
Author
Member

Added subscribers: @Sergey, @JoshuaLeung

Added subscribers: @Sergey, @JoshuaLeung
Joshua Leung changed title from Port operators to use COW to Port operators to use COW (Parent Task) 2018-04-25 13:13:58 +02:00

Added subscriber: @dfelinto

Added subscriber: @dfelinto

Added subscriber: @Scaredyfish

Added subscriber: @Scaredyfish
Member

Added subscriber: @jta

Added subscriber: @jta

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren
Member

Added subscriber: @brita

Added subscriber: @brita

Added subscriber: @codekhor

Added subscriber: @codekhor
Member

I made this quick patch to show if Blender is running with or without COW enabled as I kept getting confused with multiple Blenders while testing.
It has an include for depsgraph, so double check your includes if editing that file.

P691

I made this quick patch to show if Blender is running with or without COW enabled as I kept getting confused with multiple Blenders while testing. It has an include for depsgraph, so double check your includes if editing that file. [P691](https://archive.blender.org/developer/P691.txt)

Added subscriber: @TuomoKeskitalo

Added subscriber: @TuomoKeskitalo
Member

Added subscriber: @LazyDodo

Added subscriber: @LazyDodo
Member

fixed the wiki links, @Sergey can you transfer dependency graph design to the new wiki? (had to place a en.blender.org link for now)

fixed the wiki links, @Sergey can you transfer [dependency graph design ](https://en.blender.org/index.php/Dev:2.8/Source/Depsgraph) to the new wiki? (had to place a en.blender.org link for now)
Member

Added subscriber: @nBurn

Added subscriber: @nBurn
Member

@nBurn transferred the page, link has been updated.

@nBurn transferred the page, link has been updated.

Added subscriber: @brecht

Added subscriber: @brecht

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

Most operators appear to be working, and we will use bug tracker to handle remaining issues.

Most operators appear to be working, and we will use bug tracker to handle remaining issues.
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
10 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#54810
No description provided.