Page MenuHome

Cycles: Speedup up tangent space calculation
ClosedPublic

Authored by Sergey Sharybin (sergey) on Aug 25 2017, 10:50 PM.

Details

Summary

This patch goes away form using C++ RNA during tangent space calculation which
avoids quite a bit of overhead. This is similar to what D2702 is doing, but
there are some differences: calculation uses ccl::Mesh entirely, without any
preprocessing.

Cons:

  • Tangent is now calculated from triangles. Didn't see any difference comparing results on adult Scales model, but some more (including regression) testing is required.
  • There is some trickery to make Cycles to store UV layers if they are not used by shader directly but required to calculate tangent space.

Pros:

  • Same speed as D2702 (assuming, mikkspace.c is patched as well, see below).
  • Memory footprint is same or lower than with D2702:
    • We got rig of temporary tangent array in MikkUserData.
    • We don't need extra arrays for normals, vertices and vert-indices.
    • We still might create extra arrays for UV coordinates if shader doesn't use them itself.
  • The code is generic enough, not dependent on anything from Blender and could be moved to render/. This way other render engines will be able to calculate Blender-compatible tangents. Additionally, this will allow Cycles standalone to have support of tangents. Note: there is one dependency to Blender is to map orco back to original undeformed vertex location, but that's simple to solve.
  • The code allows threaded evaluation of tangent layers: both evaluation of multiple tangent layers of the same object in separate threads and calculating tangents of multiple objects at the same time.

Note that this path does not include miskapce.c changes from D2702, those are to
be applied separately.

There are still some TODOs here and there, but don't think it's something fully
important. If this approach is considered fine will solve those TODOs (maybe as
separate commit right after main changes, since those are more like a refactor).

Diff Detail

Repository
rB Blender
Branch
cycles_mikkspace
Build Status
Buildable 780
Build 780: arc lint + arc unit

Event Timeline

Remove residue of debug code

Yeah, that approach is definitely better - especially multithreading as much as possible is extremely important.

I guess there might be a slight difference because the getter functions are accessed through function pointers instead of inlined, but in practise I wouldn't expect it to be noticeable (especially as D2702 drastically reduces the amount of calls).

Didn't review code but general idea seems fine to me.

Update against latest master

Solved TODO.

Not sure it worth holding this patch off any longer?

Looks good to me, couldn't spot mistakes in the code.

This revision is now accepted and ready to land.Oct 10 2017, 2:33 PM
This revision was automatically updated to reflect the committed changes.