Page MenuHome

Line Art feature update: Threaded Object Loading
ClosedPublic

Authored by YimingWu (NicksBest) on May 18 2021, 3:59 PM.

Details

Summary

This patch is required to be reviewed and merged first in order to get the rest of the new functions work

This patch contains threaded object loading code for line art.

Reduced loading time to almost half of what it used to be. See statistics and test file:

(Removed a pot object because it triggers some weird code in debug mode)

Diff Detail

Repository
rB Blender

Event Timeline

YimingWu (NicksBest) requested review of this revision.May 18 2021, 3:59 PM
YimingWu (NicksBest) created this revision.

Updated to include context

YimingWu (NicksBest) edited the summary of this revision. (Show Details)May 19 2021, 10:55 AM

Updated to include context

YimingWu (NicksBest) edited the summary of this revision. (Show Details)May 19 2021, 11:02 AM

Submitting my feedback in chunks. This is the first one.

source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
338–339

How about renaming these to mat_view_proj and mat_view ?

To me "mvp" got a bit confusing until I scrolled down to see what was actually assigned to it.

Before reading it I though that it might be a "move point" or a very important "most valuable player" matrix.
So spelling it out in the name a bit more would be good.

As you noticed in the suggested new names, I also think you can drop new. As you don't really save and old matrices, right?
So these are just matrices that you calculated and stored here.

341

drop r from the name. So: v_eln

Do the same for reln in lineart_geometry_object_load as well.

347–356

Hmm, these seem to be list pointers.
So these are esentially *first, *last ListBase pointers.

Why not have these be list bases?

So instead of :

LineartEdge *contour;
LineartEdge *contour_last;

You have:

ListBase *contour_list;

It think it will be then crystal clear from just reading the name that this is a list.

365

We shouldn't use long according to our style guide:
https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Integer_Types

source/blender/gpencil_modifiers/intern/lineart/lineart_util.c
65

Why is the list base named h here?

I think just naming it list would be better.

source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
342

This doesn't seem to override anything anymore.
So change it to usage.

I think besides my comments the code looks good.

I also measured a 30% improvement on a release build in the elephant scene on my computer. (1.1 seconds to load -> 0.75 seconds to load).

However I noticed that when looking at the work distribution that the convertion to bmesh takes half of the time:

The first three seconds are spent mostly just doing the BM_mesh_bm_from_me convertion.
But we can also see that the rest of the loading operation now seems to thread quite nicely. It manages to saturate the threads so most are continuously working on tasks.

So I think that we should fix the TODO you have written in the code and thread the mesh conversion as well.

I know you had some issues with this, but I don't remember what they were.
However from looking at the code, I think you could perhaps reuse the same lineart_geometry_load_assign_thread logic for BMesh convertion as well.

So instead of converting the meshes in the DEG_OBJECT_ITER_BEGIN loop, you can queue them up and do it in parallel after all objects have been dealt with.

The only place currently in that loop where you use BMesh data is for the lineart_geometry_load_assign_thread call. And for that, you can easily replace the bm->totface with me->totface (as the face count of the Mesh and BMesh data is the same).

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
1532

use_mesh is unused.

1734

rb is unused.

1823

Same as I mentioned before, don't use long, use uintxx_t instead.

1903

Nitpick: Capitalize so after the period.

1917

Wouldn't it be better to have this check before you get the evaluated object?

So if you know that the object will be excluded either way, you don't spend any time getting the evaluated object from depsgraph.

Sebastian Parborg (zeddb) requested changes to this revision.May 19 2021, 7:05 PM
This revision now requires changes to proceed.May 19 2021, 7:05 PM

I think besides my comments the code looks good.

I also measured a 30% improvement on a release build in the elephant scene on my computer. (1.1 seconds to load -> 0.75 seconds to load).

However I noticed that when looking at the work distribution that the convertion to bmesh takes half of the time:

The first three seconds are spent mostly just doing the BM_mesh_bm_from_me convertion.
But we can also see that the rest of the loading operation now seems to thread quite nicely. It manages to saturate the threads so most are continuously working on tasks.

So I think that we should fix the TODO you have written in the code and thread the mesh conversion as well.

I know you had some issues with this, but I don't remember what they were.
However from looking at the code, I think you could perhaps reuse the same lineart_geometry_load_assign_thread logic for BMesh convertion as well.

So instead of converting the meshes in the DEG_OBJECT_ITER_BEGIN loop, you can queue them up and do it in parallel after all objects have been dealt with.

The only place currently in that loop where you use BMesh data is for the lineart_geometry_load_assign_thread call. And for that, you can easily replace the bm->totface with me->totface (as the face count of the Mesh and BMesh data is the same).

Right... the conversion needs to be in parallel for best performance, but the problem with that is that the me is only available in the loop, and can't be accessed later. Maybe I can copy a me there, that could be faster than converting to bm but it's gonna take a lot more memory.

The best best way to do this is to have it in a deg evaluation stage, where there's a special tag for evaluating line art data, that way everything is properly threaded and we don't need to worry about managing those ourselves, during this loading call we simply grab those data.

YimingWu (NicksBest) marked an inline comment as done.May 20 2021, 5:52 AM
YimingWu (NicksBest) added inline comments.
source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
1917

Fair... I'll do that. Maybe because that call wasn't typically costly, or I just bracketed my existing functions

YimingWu (NicksBest) marked 6 inline comments as done.May 24 2021, 8:23 AM
YimingWu (NicksBest) added inline comments.
source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
347–356

It's a Link list with tail. I should probably use LinkNodePair. But I manipulate the pointer on my own and there are some Marcos involved. I'll change that in a bit.

YimingWu (NicksBest) marked 4 inline comments as done.May 24 2021, 8:27 AM
YimingWu (NicksBest) added inline comments.
source/blender/gpencil_modifiers/intern/lineart/lineart_util.c
65

It was meant to be "handle" as the old name was that... I'll change those to list then.

YimingWu (NicksBest) marked an inline comment as done.

Fixed stuff in comment.

The double pointer list thing I'll need to fix in a later patch because it affects a lot of stuff.

Fixed stuff in comment.

The double pointer list thing I'll need to fix in a later patch because it affects a lot of stuff.

The issues brought up in the review should be fixed before it is committed.
For somethings it might be ok to do later, but I don't think this is one of them.

Otherwise we will accept a lot of crappy code with the promise "I'll fix it later".
There is a very high risk of the "fixing it later" never happening.

Updated to be consistent with recent naming changes.

YimingWu (NicksBest) marked an inline comment as done.May 27 2021, 1:35 PM

Updated to include BMesh conversion into worker thread.

Just to attach the latest benchmark here:

Besides my nitpicks. LGTM

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
1912

This comment is not relevant anymore as we not do this in parallel?

1915

Unused variable.

This revision is now accepted and ready to land.Jun 7 2021, 7:19 PM
This revision was automatically updated to reflect the committed changes.
YimingWu (NicksBest) marked 2 inline comments as done.