Page MenuHome

GPencil: Update-on-write using update cache
ClosedPublic

Authored by Falk David (filedescriptor) on Feb 1 2022, 5:32 PM.
Tokens
"Pterodactyl" token, awarded by shader."Love" token, awarded by gilberto_rodrigues."Love" token, awarded by Draise."Love" token, awarded by Bit."Love" token, awarded by hamza.elbarmaki."Love" token, awarded by mendio."Love" token, awarded by 295032."Love" token, awarded by johantri."Love" token, awarded by pixeltrain."Pterodactyl" token, awarded by Gavriel5578."Mountain of Wealth" token, awarded by Garek."Love" token, awarded by frogstomp."Love" token, awarded by pepeland."Love" token, awarded by antoniov.

Details

Summary

This implements the update cache described in T95401.

The cache is currently only used for drawing strokes, sculpting (using the push brush), and changing RNA properties on layers (e.g. changing the opacity or
the layer transform). Note: Making use of the cache throughout grease pencil will have to be done incrementally in other patches.

Demo on an Intel® Core™ i7-9700 CPU @ 3.00GHz with 8 cores:

Performance tests:
Test file: heavy_test_file.blend (from T91945)
Single GP object with:

  • 86 layers
  • 11k frames
  • 300k stokes
  • 13M points

OS: Windows 10
CPU: Intel(R) Xeon(R) E5-1650 v4 @ 3.60GHz

Drawing strokes (average of 10)Changing layer opacity (average of 10)Sculpting strokes (push brush, 100 strokes)
master (2022-02-02)1.1201844 s1.1050539 s0.8 - 1.1 fps
patch0.0013894 s (~ x800)0.0012322 s (~ x900)20 - 24 fps

Measurements done using --debug-depsgraph-time.

Remaining issues:

  • Fix memory leaks

Design task: T95401
Co-authored-by: @Yann Lanthony (yann-lty)

Diff Detail

Repository
rB Blender

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
  • Link to the correct task
Falk David (filedescriptor) edited the summary of this revision. (Show Details)

In general, I really like the idea of tagging only changed data and it's a great step to improve the handling of very large files that are normally used in production.

You both have done a great job!

source/blender/blenkernel/BKE_gpencil_update_cache.h
138

Not sure if this is the best naming. Struct has some C naming implications and maybe would be better to use something like BKE_gpencil_tag_data_members_update or BKE_gpencil_tag_only__members_update. Not sure about the name, we need find a better one.

source/blender/blenkernel/intern/gpencil.c
993

As this function copy data members, it's very easy to miss here something when is added to DNA struct, so it would be good to put some comments in the DNA definition about that this function needs to be update also.

source/blender/blenkernel/BKE_gpencil_update_cache.h
47

Same comment about naming... if we change the BKE function name, we must align this tag name too.

Garek (Garek) added a subscriber: Garek (Garek).
  • Rename struct_copy to light_copy
  • Simplify cache_node_update and add comments
  • Add comments to DNA for BKE_*_copy_settings functions
  • Add light updates to layers in the rna update

Co-authored-by: @Yann Lanthony (yann-lty)

  • Fix memory leak for full updates on strokes
  • Merge branch 'master'
Falk David (filedescriptor) marked 3 inline comments as done.
Falk David (filedescriptor) edited the summary of this revision. (Show Details)
This comment was removed by Falk David (filedescriptor).
  • Merge branch 'master'

This is mostly all internal to grease pencil I don't have much understanding or comments on that. Just a note about the depsgraph integration.

source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
906–928

I think it would be better to reorganize this code to make it more similar to other data types.

For the !!BKE_gpencil_check_copy_on_write_needed case, move it before RuntimeBackup like the edit mode exception. Maybe it also needs that same is_cow_explicitly_tagged check? Something like:

if (check_datablock_expanded(id_cow) && !id_node->is_cow_explicitly_tagged) {
  const ID_Type id_type = GS(id_orig->name);
  if (OB_DATA_SUPPORT_EDITMODE(id_type) && BKE_object_data_is_in_editmode(id_orig)) {
    ...
  }
  else if {id_type == ID_GD && BKE_gpencil_check_copy_on_write_needed) {
     ...
  }

Then for the other case, I think a RuntimeBackup should be implemented for grease pencil consistent with other datablocks.

  • Merge branch 'master'
  • Add RuntimeBackup for grease pencil
  • Ensure update-on-write only in active depsgraph
Falk David (filedescriptor) marked an inline comment as done.Feb 4 2022, 6:32 PM
  • Remove tagging copy-on-write tag on gpd id
  • Merge branch 'master' into patch/gpencil-update-on-write

For the depsgraph side I have some east-to-address inlined comments. Mainly need to ensure that depsgraph developers understand why things are done the way they are done.

The cache system as a whole is a bit harder for me to justify from the "is there a simpler way of dealing with performance". The design does sound reasonable, so kinda would trust the gpencil team to justify that it is a necessary "complication" to go to.
It also seems something "internal" in a sense that if there are issues we can re-iterate over it without loosing file compatibility. So unless someone else want to drop by and lead a project I'd say it is up to the gpencil team to design and implement the caching needed for painting.

The only thing is that ideally we'd need to only use the fast behavior and remove the use_gpencil_update_cache setting.

source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
895

Don't use elseafter return.

The BKE_gpencil_update_on_write_check sounds ambiguous. Maybe something BKE_gpencil_check_can_avoid_full_copy_on_write() ?

source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_gpencil.cc
17

Copyright year in new files.

46–49

Some explanation is needed about why the cache is to be freed here, and why only for active depsgraph. Something to help future depsgraph developers to understand what's and why something is going on.

  • Merge with master
  • Rename kernel function
  • Add comments
Falk David (filedescriptor) marked 2 inline comments as done.Feb 8 2022, 11:04 AM

The only thing is that ideally we'd need to only use the fast behavior and remove the use_gpencil_update_cache setting.

Yes, if we are going to remove the debug option, then we should fully move to the update cache (which should probably be done in some other patch).

Thanks for the update! From the depsgraph side it seems good now.

For the gpencil part best would be to get review from the gpencil module members.

LGTM, but keep pending because I want a double check of the patch by @Daniel Martinez Lara (pepeland) and @Matias Mendiola (mendio) to be sure the patch is working as expected.

The patch is ready to be moved to master. Thanks to both of you for your work and for such an important modification that solves one of the main problems that existed when working with heavy files. Congratulations!!

This revision is now accepted and ready to land.Feb 8 2022, 5:15 PM
Falk David (filedescriptor) planned changes to this revision.Feb 8 2022, 5:42 PM

There are a few things that we feel like need to be done before committing.

  1. The BLI_findlinkfrom function that was added should be added to the tests in source/blender/blenlib/tests/BLI_listbase_test.cc.
  2. The light tag in rna_GPencil_update should be removed for now as this was only part of our testing. It can be added after the merge in another commit.
    1. Note: The problem is that in rna_property_update there is an explicit tag DEG_id_tag_update(ptr->owner_id, ID_RECALC_COPY_ON_WRITE); which will skip the update cache.
  3. The debug boolean should be removed and the update cache should always be enabled. But it will only be used when the tagging functions are properly called and otherwise fallback to a copy-on-write.
  • Merge branch 'master' into patch/gpencil-update-on-write
  • Update copyright date
  • Add tests for BLI_findlinkfrom
  • Fix compiler warning, parameter unused
  • Remove use_gpencil_update_cache debug setting
  • Disable light tagging of layers in the rna update
  • Allow start link in BLI_findlinkfrom to be null
This revision is now accepted and ready to land.Feb 9 2022, 12:19 PM
Falk David (filedescriptor) marked an inline comment as done.Feb 9 2022, 1:47 PM
  • Update comments for iterator callback
  • Merge branch 'master' into patch/gpencil-update-on-write