diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-08-25 15:54:44 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-08-25 15:54:44 +0300 |
commit | d79fa8dc4dc28fc49dbdbecbd481bc21657f24c6 (patch) | |
tree | cf2cf35b2f01f6a70c861904e55e2896cda4cef3 /intern/mikktspace | |
parent | 49717d49715857ba595336115b7dba8d66b7f2ae (diff) |
Another optimization of tangent space calculation
Don't use quick sort for small arrays, bubble sort works way faster for small
arrays due to cache coherency. This is what qsort() from libc is doing actually.
We can also experiment unrolling some extra small arrays, for example 3 and 4
element arrays.
This reduces tangent space calculation for dragon from 3.1sec to 2.9sec.
Diffstat (limited to 'intern/mikktspace')
-rw-r--r-- | intern/mikktspace/mikktspace.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/intern/mikktspace/mikktspace.c b/intern/mikktspace/mikktspace.c index 479443805bf..2e8e58d37d4 100644 --- a/intern/mikktspace/mikktspace.c +++ b/intern/mikktspace/mikktspace.c @@ -1677,6 +1677,19 @@ static void QuickSortEdges(SEdge * pSortBuffer, int iLeft, int iRight, const int } return; } + else if(iElems < 16) { + int i, j; + for (i = 0; i < iElems - 1; i++) { + for (j = 0; j < iElems - i - 1; j++) { + int index = iLeft + j; + if (pSortBuffer[index].array[channel] > pSortBuffer[index + 1].array[channel]) { + sTmp = pSortBuffer[index]; + pSortBuffer[index] = pSortBuffer[index]; + pSortBuffer[index + 1] = sTmp; + } + } + } + } // Random t=uSeed&31; |