Fix: DEG: Image updates are flushed for initial evaluation #115240

Closed
Omar Emara wants to merge 1 commits from OmarEmaraDev:fix-depsgraph-flush-editors into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Visibility updates as part of the first depsgraph evaluation when
data-blocks first become visible are flushed to editors for Image IDs.

A check does exist to avoid flushing in those cases, however, it uses
the COW expanded status of the ID, which fails for IDs that do not use
COW.

This patch fixes that by explicitly passing the original value of the
graph visibility update flag before getting reset, which is then used in
the aforementioned check.

Visibility updates as part of the first depsgraph evaluation when data-blocks first become visible are flushed to editors for Image IDs. A check does exist to avoid flushing in those cases, however, it uses the COW expanded status of the ID, which fails for IDs that do not use COW. This patch fixes that by explicitly passing the original value of the graph visibility update flag before getting reset, which is then used in the aforementioned check.
Omar Emara added the
Interest
Dependency Graph
Module
Core
labels 2023-11-21 14:42:38 +01:00
Omar Emara added 1 commit 2023-11-21 14:42:48 +01:00
ba78c98b69 Fix: DEG: Image updates are flushed for initial evaluation
Visibility updates as part of the first depsgraph evaluation when
data-blocks first become visible are flushed to editors for Image IDs.

A check does exist to avoid flushing in those cases, however, it uses
the COW expanded status of the ID, which fails for IDs that do not use
COW.

This patch fixes that by explicitly passing the original value of the
graph visibility update flag before getting reset, which is then used in
the aforementioned check.
Omar Emara requested review from Sergey Sharybin 2023-11-21 14:43:05 +01:00

This changes the logic from "inform editors about ID change on next evaluation after it was fully evaluated" to "inform editors about ID changes on a second depsgraph evaluation after it was tagged for visibility updates". From intuitive understanding of the code this means that with the proposed change adding cube to scene will immediately inform editors about change.

What does this patch address on user level? Knowing that would help thinking of a better solution.

This changes the logic from "inform editors about ID change on next evaluation after it was fully evaluated" to "inform editors about ID changes on a second depsgraph evaluation after it was tagged for visibility updates". From intuitive understanding of the code this means that with the proposed change adding cube to scene will immediately inform editors about change. What does this patch address on user level? Knowing that would help thinking of a better solution.
Author
Member

Yah, sorry, my knowledge of the depsgraph is not great.
Well, I was just trying to handle the comment:

TODO: image data-blocks do not use COW, so might not be detected correctly.

On the user level, when the user edits a compositor node tree that contains an Image node that references an image ID, that image ID will get its reclac flag set due to it "becoming visible" when refreshing the compositor's depsgraph. The image ID didn't change, yet its reclac flag says it changed, which the problem I am trying to solve.

Yah, sorry, my knowledge of the depsgraph is not great. Well, I was just trying to handle the comment: > TODO: image data-blocks do not use COW, so might not be detected correctly. On the user level, when the user edits a compositor node tree that contains an Image node that references an image ID, that image ID will get its reclac flag set due to it "becoming visible" when refreshing the compositor's depsgraph. The image ID didn't change, yet its reclac flag says it changed, which the problem I am trying to solve.
Author
Member

@Sergey This is what happens when I edit a node tree that contains an image node, evem though the image itself didn't change. Notice:

graph_id_tag_update: id=IMmandril_color.tif flags=LEGACY_0 source=VISIBILITY

And:

Accumulated recalc bits for IMmandril_color.tif: 4286541699

Depsgraph debug output:

graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT
graph_id_tag_update: id=NTCompositing Nodetree flags=ID_RECALC_NTREE_OUTPUT source=USER_EDIT
graph_id_tag_update: id=NTCompositing Nodetree flags=ID_RECALC_NTREE_OUTPUT source=USER_EDIT
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT
Removed 7 relations to no-op nodes
graph_id_tag_update: id=SCScene flags=COPY_ON_WRITE source=RELATIONS
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=RELATIONS
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE, ID_RECALC_NTREE_OUTPUT source=RELATIONS
graph_id_tag_update: id=OBCamera flags=TRANSFORM, GEOMETRY, COPY_ON_WRITE source=RELATIONS
graph_id_tag_update: id=CACamera flags=COPY_ON_WRITE source=RELATIONS
Depsgraph built in 0.000511 seconds.
graph_id_tag_update: id=SCScene flags=COPY_ON_WRITE source=VISIBILITY
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=VISIBILITY
graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=VISIBILITY
graph_id_tag_update: id=IMViewer Node flags=LEGACY_0 source=VISIBILITY
graph_id_tag_update: id=IMmandril_color.tif flags=LEGACY_0 source=VISIBILITY
graph_id_tag_update: id=OBCamera flags=TRANSFORM, GEOMETRY, COPY_ON_WRITE source=VISIBILITY
graph_id_tag_update: id=CACamera flags=COPY_ON_WRITE source=VISIBILITY
Operation is entry point for update: VISIBILITY()
Operation is entry point for update: PARAMETERS_ENTRY()
Operation is entry point for update: SEQUENCES_EVAL()
Operation is entry point for update: PARAMETERS_EVAL()
Operation is entry point for update: COPY_ON_WRITE()
Operation is entry point for update: COPY_ON_WRITE()
Operation is entry point for update: SOUND_EVAL()
Operation is entry point for update: VISIBILITY()
Operation is entry point for update: TRANSFORM_SIMULATION_INIT()
Operation is entry point for update: TRANSFORM_LOCAL()
Operation is entry point for update: TRANSFORM_EVAL()
Operation is entry point for update: PARAMETERS_EVAL()
Operation is entry point for update: NTREE_OUTPUT()
Operation is entry point for update: PARAMETERS_ENTRY()
Operation is entry point for update: COPY_ON_WRITE()
Operation is entry point for update: VISIBILITY()
Operation is entry point for update: TRANSFORM_FINAL()
Operation is entry point for update: PARAMETERS_EXIT()
Operation is entry point for update: AUDIO_VOLUME()
Operation is entry point for update: TRANSFORM_INIT()
Operation is entry point for update: PARAMETERS_ENTRY()
Operation is entry point for update: GENERIC_DATABLOCK_UPDATE()
Operation is entry point for update: COPY_ON_WRITE()
Operation is entry point for update: PARAMETERS_EXIT()
Operation is entry point for update: GENERIC_DATABLOCK_UPDATE()
Operation is entry point for update: AUDIO_ENTRY()
Operation is entry point for update: SCENE_EVAL()
Operation is entry point for update: PARAMETERS_EXIT()
Operation is entry point for update: PARAMETERS_EVAL()
Accumulated recalc bits for SCScene: 8192
Accumulated recalc bits for NTCompositing Nodetree: 33562624
Accumulated recalc bits for IMViewer Node: 4286541699
Accumulated recalc bits for IMmandril_color.tif: 4286541699
Accumulated recalc bits for OBCamera: 8195
Accumulated recalc bits for CACamera: 8192
deg_evaluate_copy_on_write on CACamera (0x7fc269918908)
deg_evaluate_copy_on_write on OBCamera (0x7fc26a708608)
deg_evaluate_copy_on_write on NTCompositing Nodetree (0x7fc2b8f34388)
deg_evaluate_copy_on_write on SCScene (0x7fc26a6c7808)
BKE_object_eval_local_transform on OBCamera (0x7fc26a708608)
SEQ_eval_sequences on SCScene (0x7fc26a6c7808)
BKE_object_eval_transform_final on OBCamera (0x7fc26a708608)
Depsgraph updated in 0.000628 seconds.
Depsgraph evaluation FPS: -nan
[SCScene :: View Layer]: Operation is entry point for update: COPY_ON_WRITE()
[SCScene :: View Layer]: Operation is entry point for update: NTREE_OUTPUT()
[SCScene :: View Layer]: Accumulated recalc bits for NTCompositing Nodetree: 33562624
[SCScene :: View Layer]: deg_evaluate_copy_on_write on NTCompositing Nodetree (0x7fc2822ce988)
Depsgraph updated in 0.000124 seconds.
Depsgraph evaluation FPS: 0.057334
@Sergey This is what happens when I edit a node tree that contains an image node, evem though the image itself didn't change. Notice: ``` graph_id_tag_update: id=IMmandril_color.tif flags=LEGACY_0 source=VISIBILITY ``` And: ``` Accumulated recalc bits for IMmandril_color.tif: 4286541699 ``` Depsgraph debug output: ``` graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT graph_id_tag_update: id=NTCompositing Nodetree flags=ID_RECALC_NTREE_OUTPUT source=USER_EDIT graph_id_tag_update: id=NTCompositing Nodetree flags=ID_RECALC_NTREE_OUTPUT source=USER_EDIT graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=USER_EDIT Removed 7 relations to no-op nodes graph_id_tag_update: id=SCScene flags=COPY_ON_WRITE source=RELATIONS graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=RELATIONS graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE, ID_RECALC_NTREE_OUTPUT source=RELATIONS graph_id_tag_update: id=OBCamera flags=TRANSFORM, GEOMETRY, COPY_ON_WRITE source=RELATIONS graph_id_tag_update: id=CACamera flags=COPY_ON_WRITE source=RELATIONS Depsgraph built in 0.000511 seconds. graph_id_tag_update: id=SCScene flags=COPY_ON_WRITE source=VISIBILITY graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=VISIBILITY graph_id_tag_update: id=NTCompositing Nodetree flags=COPY_ON_WRITE source=VISIBILITY graph_id_tag_update: id=IMViewer Node flags=LEGACY_0 source=VISIBILITY graph_id_tag_update: id=IMmandril_color.tif flags=LEGACY_0 source=VISIBILITY graph_id_tag_update: id=OBCamera flags=TRANSFORM, GEOMETRY, COPY_ON_WRITE source=VISIBILITY graph_id_tag_update: id=CACamera flags=COPY_ON_WRITE source=VISIBILITY Operation is entry point for update: VISIBILITY() Operation is entry point for update: PARAMETERS_ENTRY() Operation is entry point for update: SEQUENCES_EVAL() Operation is entry point for update: PARAMETERS_EVAL() Operation is entry point for update: COPY_ON_WRITE() Operation is entry point for update: COPY_ON_WRITE() Operation is entry point for update: SOUND_EVAL() Operation is entry point for update: VISIBILITY() Operation is entry point for update: TRANSFORM_SIMULATION_INIT() Operation is entry point for update: TRANSFORM_LOCAL() Operation is entry point for update: TRANSFORM_EVAL() Operation is entry point for update: PARAMETERS_EVAL() Operation is entry point for update: NTREE_OUTPUT() Operation is entry point for update: PARAMETERS_ENTRY() Operation is entry point for update: COPY_ON_WRITE() Operation is entry point for update: VISIBILITY() Operation is entry point for update: TRANSFORM_FINAL() Operation is entry point for update: PARAMETERS_EXIT() Operation is entry point for update: AUDIO_VOLUME() Operation is entry point for update: TRANSFORM_INIT() Operation is entry point for update: PARAMETERS_ENTRY() Operation is entry point for update: GENERIC_DATABLOCK_UPDATE() Operation is entry point for update: COPY_ON_WRITE() Operation is entry point for update: PARAMETERS_EXIT() Operation is entry point for update: GENERIC_DATABLOCK_UPDATE() Operation is entry point for update: AUDIO_ENTRY() Operation is entry point for update: SCENE_EVAL() Operation is entry point for update: PARAMETERS_EXIT() Operation is entry point for update: PARAMETERS_EVAL() Accumulated recalc bits for SCScene: 8192 Accumulated recalc bits for NTCompositing Nodetree: 33562624 Accumulated recalc bits for IMViewer Node: 4286541699 Accumulated recalc bits for IMmandril_color.tif: 4286541699 Accumulated recalc bits for OBCamera: 8195 Accumulated recalc bits for CACamera: 8192 deg_evaluate_copy_on_write on CACamera (0x7fc269918908) deg_evaluate_copy_on_write on OBCamera (0x7fc26a708608) deg_evaluate_copy_on_write on NTCompositing Nodetree (0x7fc2b8f34388) deg_evaluate_copy_on_write on SCScene (0x7fc26a6c7808) BKE_object_eval_local_transform on OBCamera (0x7fc26a708608) SEQ_eval_sequences on SCScene (0x7fc26a6c7808) BKE_object_eval_transform_final on OBCamera (0x7fc26a708608) Depsgraph updated in 0.000628 seconds. Depsgraph evaluation FPS: -nan [SCScene :: View Layer]: Operation is entry point for update: COPY_ON_WRITE() [SCScene :: View Layer]: Operation is entry point for update: NTREE_OUTPUT() [SCScene :: View Layer]: Accumulated recalc bits for NTCompositing Nodetree: 33562624 [SCScene :: View Layer]: deg_evaluate_copy_on_write on NTCompositing Nodetree (0x7fc2822ce988) Depsgraph updated in 0.000124 seconds. Depsgraph evaluation FPS: 0.057334 ```

I think there are two things here then:

  1. The TODO about images in the flush_editors_id_update.
  2. The fact that the Image gets tagged for full update when new dependency graph is constructed.

The first one is annoying, but it is not the place where image is tagged. For the compositor depsgraph the deg_editors_id_update is not executed because compositor's depsgraph is not the active one.

The second one seems to be much more important in the context of avoiding unneeded updates on compositoor depsgraph changes. A quick test for whether it is the case would be to do something like this in graph_tag_ids_for_visible_update (or something similar):

    if (!(id_type == ID_IM && flag == 0)) {
      graph_id_tag_update(bmain, graph, id_node->id_orig, flags, DEG_UPDATE_SOURCE_VISIBILITY);
    }

If that helps performance, then we can look into correctness of such change and do tweaks if needed.

I think there are two things here then: 1. The TODO about images in the `flush_editors_id_update`. 2. The fact that the Image gets tagged for full update when new dependency graph is constructed. The first one is annoying, but it is not the place where image is tagged. For the compositor depsgraph the `deg_editors_id_update` is not executed because compositor's depsgraph is not the active one. The second one seems to be much more important in the context of avoiding unneeded updates on compositoor depsgraph changes. A quick test for whether it is the case would be to do something like this in `graph_tag_ids_for_visible_update` (or something similar): ``` if (!(id_type == ID_IM && flag == 0)) { graph_id_tag_update(bmain, graph, id_node->id_orig, flags, DEG_UPDATE_SOURCE_VISIBILITY); } ``` If that helps performance, then we can look into correctness of such change and do tweaks if needed.
Author
Member

@Sergey I see. But to clarify, the performance improvement in my case is indirect, since the superfluous tag invalidates the image cache every time the compositor executes, which defies the point of the cache.

That change looks like it will alleviate the problem, but I will confirm it in a bit.

@Sergey I see. But to clarify, the performance improvement in my case is indirect, since the superfluous tag invalidates the image cache every time the compositor executes, which defies the point of the cache. That change looks like it will alleviate the problem, but I will confirm it in a bit.
Author
Member

The little code snippet does produce the intended outcome in my use case.

The little code snippet does produce the intended outcome in my use case.

Good to know!

I'll need to double-check, but I think we can actually skip such depsgraph tags on graph creation for all IDs which are not covered by the COW.

Good to know! I'll need to double-check, but I think we can actually skip such depsgraph tags on graph creation for all IDs which are not covered by the COW.
Omar Emara closed this pull request 2023-12-01 18:07:16 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
2 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#115240
No description provided.