bdk-blender/intern/mikktspace
Lukas Stockner c486da0238 Mikktspace: Reduce number of data queries to caller
The current code for computing tangents is not exactly fast.
This has been a long-standing issue, and recently came up again with T97378.

The main bottleneck is fetching the mesh data, since it's handled through a callback system and each vertex might have its data queried dozens of times.

I've tried a lot of things to optimize `mikktspace.c`, but unfortunately most weren't that useful:
- Vectorizing SVec3 gives a ~5% speedup, but I'm not sure if the additional ~70 lines of code are worth it
- Keeping an internal copy of the data instead of re-querying all the time helps a lot (~50-60% time reduction), but requires a lot of extra memory (~100 byte per face)
- Going C++ and replacing the internal quicksort with std::sort shows no difference
- Restructuring the entire file to be a header-only library so that the callbacks can be inlined gives ~10% reduction, but is a major change and deviation from the original library

In the end, two simple fixes that actually help remain:
- Don't re-query the number of faces in each loop iteration
- Don't bother looking for identical vertices if there's only one vertex with that hash

With this, time for the test case in T97378 goes from 6.64sec to 4.92sec. It's something I guess.

I feel like completely refactoring this library would not be a bad idea at some point, but for now it does the job...

Differential Revision: https://developer.blender.org/D14675
2022-04-23 15:09:41 +02:00
..
CMakeLists.txt File headers: SPDX License migration 2022-02-11 09:14:36 +11:00
mikktspace.c Mikktspace: Reduce number of data queries to caller 2022-04-23 15:09:41 +02:00
mikktspace.h File headers: use SPDX for Zlib license 2022-02-11 14:23:55 +11:00
README.md Docs: Add readme for mikktspace 2021-05-23 13:57:22 -04:00

MikkTSpace

A common standard for tangent space used in baking tools to produce normal maps.

More information can be found at http://www.mikktspace.com/.