Page MenuHome

Draw Cache: avoid recalculating 'poly_normals'
ClosedPublic

Authored by Germano Cavalcante (mano-wii) on Jun 7 2021, 11:15 PM.

Details

Summary

Polygon normals are already calculated at the end of the modifier
evaluation and are stored in the CustomData CD_NORMAL.

We also have a dirty flag to make sure they need to be recalculated:
mesh->runtime.cd_dirty_poly & CD_MASK_NORMAL

This patch proposes to call BKE_mesh_ensure_normals_for_display to
avoid recalculating poly_normals.

The downside is that vert_normals can be calculated too, but I haven't
found any cases where this happens.

Benchmark

master:PATCH:
looptris_test:Average: 3.995076 FPSAverage: 4.047470 FPS
rdata 11ms iter 91ms (frame 235ms)rdata 11ms iter 86ms (frame 233ms)
subdiv_mesh_cage_and_final:Average: 1.884492 FPSAverage: 1.900114 FPS
rdata 7ms iter 42ms (frame 268ms)rdata 7ms iter 39ms (frame 265ms)
rdata 7ms iter 44ms (frame 259ms)rdata 7ms iter 42ms (frame 257ms)
subdiv_mesh_final_only:Average: 6.245944 FPSAverage: 6.289000 FPS
rdata 3ms iter 23ms (frame 153ms)rdata 3ms iter 21ms (frame 154ms)
subdiv_mesh_final_only_ledge:Average: 6.263482 FPSAverage: 6.187218 FPS
rdata 3ms iter 23ms (frame 156ms)rdata 3ms iter 22ms (frame 154ms)

Diff Detail

Repository
rB Blender
Branch
master
Build Status
Buildable 15017
Build 15017: arc lint + arc unit

Event Timeline

Germano Cavalcante (mano-wii) requested review of this revision.Jun 7 2021, 11:15 PM
Germano Cavalcante (mano-wii) created this revision.

I would split the BKE_mesh_ensure_normals_for_display into smaller functions and only invoke what we need. Makes it more obvious what we need and wouldn't do more if the mesh is in a certain state.

About the vertex normals. Yes I haven't been able to trigger that part also.

I would split the BKE_mesh_ensure_normals_for_display into smaller functions and only invoke what we need.

It is not so simple to split into smaller functions since in the vert_normals calculation is very mixed with poly_normals.
We could create another function that only calculate poly_normals or add a parameter "const bool only_face_normals".
(I'm tempted to the second option).

My suggestion isn't worth the effort at this moment. We can optimize later.

This revision is now accepted and ready to land.Jun 9 2021, 4:31 PM