Page MenuHome

Avoid double initialization of MeshBatchCache
AbandonedPublic

Authored by Jacques Lucke (JacquesLucke) on Sep 24 2018, 12:04 PM.

Details

Summary

Before this the MeshBatchCache is reinitialized twice every time something other then the active vertex group changed.

Diff Detail

Repository
rB Blender
Branch
cache_invalidation_fix (branched from blender2.8)
Build Status
Buildable 2102
Build 2102: arc lint + arc unit

Event Timeline

Brecht Van Lommel (brecht) added inline comments.
source/blender/draw/intern/draw_cache_impl_mesh.c
1742

Code style is:

}
else {
This revision is now accepted and ready to land.Sep 24 2018, 12:22 PM

What's the point of this? Also, negative group index (no active group) does not mean there is no weight data required. It is a perfectly feasible condition in weight painting, and 2.79 actually has special pink highlight for it.

Why should there be weight data if there is not actually a vertex group? Not sure what pink highlight you mean.
This mesh_batch_cache_get__check_vertex_group function originally comes from here: https://developer.blender.org/D3716
The function just makes sure that no MeshBatchCache with weight data from another vertex group is returned. Maybe the function could be renamed.

Because weight painting drawing uses vertex weight color data, and you can be in weight paint mode without an active vertex group.

Also note that I have a pending patch that does more substantive changes to this area of code: https://developer.blender.org/D3722

I see. So the triangles_with_weights property is used for the "default weights" then?

ok, so when you work in that area anyway you can also take care of this update issue I linked before? Then I would just abandon this patch.

Won't it be enough to just check if triangles_with_weights is NULL here, instead of vertex_group_index?

If in weight paint mode you select a bone without a matching vertex group, there would be no active vertex group; however you are still in weight paint mode, and actually trying to paint would automatically create that group iirc.

This issue is actually not related to bones at all. Here is a smaller file to reproduce the bug that existed before:


Before: when you selected a different group in the panel, the viewport did not draw the selected group immediately.

Checking for NULL is not enough I think. Somehow we need to know if the weight data in the cache corresponds to the selected vertex group or not.

I'm not very familiar with the code though, you can probably fix this in other ways as well.

How can I reproduce the problem this specific patch tries to fix so I can test it?

Don't know haha
I discovered this problem on the weekend when I simulated the first patch in my head ^^

Imagine the cache already has is_dirty set to true. Then, when mesh_batch_cache_get__check_vertex_group is called, the cache is reinitialized in the first call to mesh_batch_cache_get. Then the check cache->vertex_group_index != defgroup is true (because defgroup >= 0 and vertex_group_index = -1) and is_dirty is set to true again. This results in a second re-initialization of the cache in the second call to mesh_batch_cache_get.

It is not a super critical problem, just a bit ugly. And depending on how long it takes to reinitialize the cache, it can be a performance problem.

This should be fixed by the changes in D3722.