2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2023-10-07 12:17:39 +00:00
|
|
|
Copyright (c) 2006-2023, assimp team
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 03:48:29 +00:00
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Implementation of the post processing step to improve the cache locality of a mesh.
|
|
|
|
* <br>
|
|
|
|
* The algorithm is roughly basing on this paper:
|
|
|
|
* http://www.cs.princeton.edu/gfx/pubs/Sander_2007_%3ETR/tipsy.pdf
|
2019-06-10 21:26:00 +00:00
|
|
|
* .. although overdraw reduction isn't implemented yet ...
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// internal headers
|
2019-06-10 21:26:00 +00:00
|
|
|
#include "PostProcessing/ImproveCacheLocality.h"
|
|
|
|
#include "Common/VertexTriangleAdjacency.h"
|
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/StringUtils.h>
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/postprocess.h>
|
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stack>
|
|
|
|
|
2023-10-07 12:17:39 +00:00
|
|
|
namespace Assimp {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
2023-10-07 12:17:39 +00:00
|
|
|
ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() :
|
|
|
|
mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) {
|
2019-06-10 21:26:00 +00:00
|
|
|
// empty
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns whether the processing step is present in the given flag field.
|
2023-10-07 12:17:39 +00:00
|
|
|
bool ImproveCacheLocalityProcess::IsActive(unsigned int pFlags) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return (pFlags & aiProcess_ImproveCacheLocality) != 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Setup configuration
|
2023-10-07 12:17:39 +00:00
|
|
|
void ImproveCacheLocalityProcess::SetupProperties(const Importer *pImp) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// AI_CONFIG_PP_ICL_PTCACHE_SIZE controls the target cache size for the optimizer
|
2023-10-07 12:17:39 +00:00
|
|
|
mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE, PP_ICL_PTCACHE_SIZE);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Executes the post processing step on the given imported data.
|
2023-10-07 12:17:39 +00:00
|
|
|
void ImproveCacheLocalityProcess::Execute(aiScene *pScene) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!pScene->mNumMeshes) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess skipped; there are no meshes");
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess begin");
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
float out = 0.f;
|
|
|
|
unsigned int numf = 0, numm = 0;
|
2023-10-07 12:17:39 +00:00
|
|
|
for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) {
|
|
|
|
const float res = ProcessMesh(pScene->mMeshes[a], a);
|
2015-05-19 03:57:13 +00:00
|
|
|
if (res) {
|
|
|
|
numf += pScene->mMeshes[a]->mNumFaces;
|
2023-10-07 12:17:39 +00:00
|
|
|
out += res;
|
2015-05-19 03:57:13 +00:00
|
|
|
++numm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!DefaultLogger::isNullLogger()) {
|
2019-03-14 16:37:28 +00:00
|
|
|
if (numf > 0) {
|
2021-05-13 09:25:27 +00:00
|
|
|
ASSIMP_LOG_INFO("Cache relevant are ", numm, " meshes (", numf, " faces). Average output ACMR is ", out / numf);
|
2019-03-14 16:37:28 +00:00
|
|
|
}
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess finished. ");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 12:17:39 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static ai_real calculateInputACMR(aiMesh *pMesh, const aiFace *const pcEnd,
|
|
|
|
unsigned int configCacheDepth, unsigned int meshNum) {
|
|
|
|
ai_real fACMR = 0.0f;
|
|
|
|
unsigned int *piFIFOStack = new unsigned int[configCacheDepth];
|
|
|
|
memset(piFIFOStack, 0xff, configCacheDepth * sizeof(unsigned int));
|
|
|
|
unsigned int *piCur = piFIFOStack;
|
|
|
|
const unsigned int *const piCurEnd = piFIFOStack + configCacheDepth;
|
|
|
|
|
|
|
|
// count the number of cache misses
|
|
|
|
unsigned int iCacheMisses = 0;
|
|
|
|
for (const aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) {
|
|
|
|
for (unsigned int qq = 0; qq < 3; ++qq) {
|
|
|
|
bool bInCache = false;
|
|
|
|
for (unsigned int *pp = piFIFOStack; pp < piCurEnd; ++pp) {
|
|
|
|
if (*pp == pcFace->mIndices[qq]) {
|
|
|
|
// the vertex is in cache
|
|
|
|
bInCache = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bInCache) {
|
|
|
|
++iCacheMisses;
|
|
|
|
if (piCurEnd == piCur) {
|
|
|
|
piCur = piFIFOStack;
|
|
|
|
}
|
|
|
|
*piCur++ = pcFace->mIndices[qq];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] piFIFOStack;
|
|
|
|
fACMR = (ai_real)iCacheMisses / pMesh->mNumFaces;
|
|
|
|
if (3.0 == fACMR) {
|
|
|
|
char szBuff[128]; // should be sufficiently large in every case
|
|
|
|
|
|
|
|
// the JoinIdenticalVertices process has not been executed on this
|
|
|
|
// mesh, otherwise this value would normally be at least minimally
|
|
|
|
// smaller than 3.0 ...
|
|
|
|
ai_snprintf(szBuff, 128, "Mesh %u: Not suitable for vcache optimization", meshNum);
|
|
|
|
ASSIMP_LOG_WARN(szBuff);
|
|
|
|
return static_cast<ai_real>(0.f);
|
|
|
|
}
|
|
|
|
return fACMR;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Improves the cache coherency of a specific mesh
|
2023-10-07 12:17:39 +00:00
|
|
|
ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshNum) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// TODO: rewrite this to use std::vector or boost::shared_array
|
2019-06-10 21:26:00 +00:00
|
|
|
ai_assert(nullptr != pMesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Check whether the input data is valid
|
|
|
|
// - there must be vertices and faces
|
|
|
|
// - all faces must be triangulated or we can't operate on them
|
|
|
|
if (!pMesh->HasFaces() || !pMesh->HasPositions())
|
2019-06-10 21:26:00 +00:00
|
|
|
return static_cast<ai_real>(0.f);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (pMesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_ERROR("This algorithm works on triangle meshes only");
|
2019-06-10 21:26:00 +00:00
|
|
|
return static_cast<ai_real>(0.f);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 12:17:39 +00:00
|
|
|
if (pMesh->mNumVertices <= mConfigCacheDepth) {
|
2019-06-10 21:26:00 +00:00
|
|
|
return static_cast<ai_real>(0.f);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 21:26:00 +00:00
|
|
|
ai_real fACMR = 3.f;
|
2023-10-07 12:17:39 +00:00
|
|
|
const aiFace *const pcEnd = pMesh->mFaces + pMesh->mNumFaces;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Input ACMR is for logging purposes only
|
2023-10-07 12:17:39 +00:00
|
|
|
if (!DefaultLogger::isNullLogger()) {
|
|
|
|
fACMR = calculateInputACMR(pMesh, pcEnd, mConfigCacheDepth, meshNum);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// first we need to build a vertex-triangle adjacency list
|
2023-10-07 12:17:39 +00:00
|
|
|
VertexTriangleAdjacency adj(pMesh->mFaces, pMesh->mNumFaces, pMesh->mNumVertices, true);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// build a list to store per-vertex caching time stamps
|
2023-10-07 12:17:39 +00:00
|
|
|
std::vector<unsigned int> piCachingStamps;
|
|
|
|
piCachingStamps.resize(pMesh->mNumVertices);
|
|
|
|
memset(&piCachingStamps[0], 0x0, pMesh->mNumVertices * sizeof(unsigned int));
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// allocate an empty output index buffer. We store the output indices in one large array.
|
|
|
|
// Since the number of triangles won't change the input faces can be reused. This is how
|
|
|
|
// we save thousands of redundant mini allocations for aiFace::mIndices
|
2023-10-07 12:17:39 +00:00
|
|
|
const unsigned int iIdxCnt = pMesh->mNumFaces * 3;
|
|
|
|
std::vector<unsigned int> piIBOutput;
|
|
|
|
piIBOutput.resize(iIdxCnt);
|
|
|
|
std::vector<unsigned int>::iterator piCSIter = piIBOutput.begin();
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// allocate the flag array to hold the information
|
|
|
|
// whether a face has already been emitted or not
|
2023-10-07 12:17:39 +00:00
|
|
|
std::vector<bool> abEmitted(pMesh->mNumFaces, false);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// dead-end vertex index stack
|
2023-10-07 12:17:39 +00:00
|
|
|
std::stack<unsigned int, std::vector<unsigned int>> sDeadEndVStack;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// create a copy of the piNumTriPtr buffer
|
2023-10-07 12:17:39 +00:00
|
|
|
unsigned int *const piNumTriPtr = adj.mLiveTriangles;
|
2015-05-19 03:57:13 +00:00
|
|
|
const std::vector<unsigned int> piNumTriPtrNoModify(piNumTriPtr, piNumTriPtr + pMesh->mNumVertices);
|
|
|
|
|
|
|
|
// get the largest number of referenced triangles and allocate the "candidate buffer"
|
2023-10-07 12:17:39 +00:00
|
|
|
unsigned int iMaxRefTris = 0;
|
|
|
|
{
|
|
|
|
const unsigned int *piCur = adj.mLiveTriangles;
|
|
|
|
const unsigned int *const piCurEnd = adj.mLiveTriangles + pMesh->mNumVertices;
|
|
|
|
for (; piCur != piCurEnd; ++piCur) {
|
|
|
|
iMaxRefTris = std::max(iMaxRefTris, *piCur);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 16:51:12 +00:00
|
|
|
ai_assert(iMaxRefTris > 0);
|
2023-10-07 12:17:39 +00:00
|
|
|
std::vector<unsigned int> piCandidates;
|
|
|
|
piCandidates.resize(iMaxRefTris * 3);
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int iCacheMisses = 0;
|
|
|
|
|
|
|
|
// ...................................................................................
|
|
|
|
/** PSEUDOCODE for the algorithm
|
|
|
|
|
|
|
|
A = Build-Adjacency(I) Vertex-triangle adjacency
|
|
|
|
L = Get-Triangle-Counts(A) Per-vertex live triangle counts
|
|
|
|
C = Zero(Vertex-Count(I)) Per-vertex caching time stamps
|
|
|
|
D = Empty-Stack() Dead-end vertex stack
|
|
|
|
E = False(Triangle-Count(I)) Per triangle emitted flag
|
|
|
|
O = Empty-Index-Buffer() Empty output buffer
|
|
|
|
f = 0 Arbitrary starting vertex
|
|
|
|
s = k+1, i = 1 Time stamp and cursor
|
|
|
|
while f >= 0 For all valid fanning vertices
|
|
|
|
N = Empty-Set() 1-ring of next candidates
|
|
|
|
for each Triangle t in Neighbors(A, f)
|
|
|
|
if !Emitted(E,t)
|
|
|
|
for each Vertex v in t
|
|
|
|
Append(O,v) Output vertex
|
|
|
|
Push(D,v) Add to dead-end stack
|
|
|
|
Insert(N,v) Register as candidate
|
|
|
|
L[v] = L[v]-1 Decrease live triangle count
|
|
|
|
if s-C[v] > k If not in cache
|
|
|
|
C[v] = s Set time stamp
|
|
|
|
s = s+1 Increment time stamp
|
|
|
|
E[t] = true Flag triangle as emitted
|
|
|
|
Select next fanning vertex
|
|
|
|
f = Get-Next-Vertex(I,i,k,N,C,s,L,D)
|
|
|
|
return O
|
|
|
|
*/
|
|
|
|
// ...................................................................................
|
|
|
|
|
|
|
|
int ivdx = 0;
|
|
|
|
int ics = 1;
|
2023-10-07 12:17:39 +00:00
|
|
|
int iStampCnt = mConfigCacheDepth + 1;
|
|
|
|
while (ivdx >= 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
unsigned int icnt = piNumTriPtrNoModify[ivdx];
|
2023-10-07 12:17:39 +00:00
|
|
|
unsigned int *piList = adj.GetAdjacentTriangles(ivdx);
|
|
|
|
std::vector<unsigned int>::iterator piCurCandidate = piCandidates.begin();
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// get all triangles in the neighborhood
|
2023-10-07 12:17:39 +00:00
|
|
|
for (unsigned int tri = 0; tri < icnt; ++tri) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// if they have not yet been emitted, add them to the output IB
|
|
|
|
const unsigned int fidx = *piList++;
|
2023-10-07 12:17:39 +00:00
|
|
|
if (!abEmitted[fidx]) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// so iterate through all vertices of the current triangle
|
2023-10-07 12:17:39 +00:00
|
|
|
const aiFace *pcFace = &pMesh->mFaces[fidx];
|
2018-04-23 09:33:48 +00:00
|
|
|
unsigned nind = pcFace->mNumIndices;
|
|
|
|
for (unsigned ind = 0; ind < nind; ind++) {
|
|
|
|
unsigned dp = pcFace->mIndices[ind];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// the current vertex won't have any free triangles after this step
|
|
|
|
if (ivdx != (int)dp) {
|
|
|
|
// append the vertex to the dead-end stack
|
|
|
|
sDeadEndVStack.push(dp);
|
|
|
|
|
|
|
|
// register as candidate for the next step
|
|
|
|
*piCurCandidate++ = dp;
|
|
|
|
|
|
|
|
// decrease the per-vertex triangle counts
|
|
|
|
piNumTriPtr[dp]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// append the vertex to the output index buffer
|
|
|
|
*piCSIter++ = dp;
|
|
|
|
|
|
|
|
// if the vertex is not yet in cache, set its cache count
|
2023-10-07 12:17:39 +00:00
|
|
|
if (iStampCnt - piCachingStamps[dp] > mConfigCacheDepth) {
|
2015-05-19 03:57:13 +00:00
|
|
|
piCachingStamps[dp] = iStampCnt++;
|
|
|
|
++iCacheMisses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// flag triangle as emitted
|
|
|
|
abEmitted[fidx] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the vertex has now no living adjacent triangles anymore
|
|
|
|
piNumTriPtr[ivdx] = 0;
|
|
|
|
|
|
|
|
// get next fanning vertex
|
|
|
|
ivdx = -1;
|
|
|
|
int max_priority = -1;
|
2023-10-07 12:17:39 +00:00
|
|
|
for (std::vector<unsigned int>::iterator piCur = piCandidates.begin(); piCur != piCurCandidate; ++piCur) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const unsigned int dp = *piCur;
|
|
|
|
|
|
|
|
// must have live triangles
|
2023-10-07 12:17:39 +00:00
|
|
|
if (piNumTriPtr[dp] > 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
int priority = 0;
|
|
|
|
|
|
|
|
// will the vertex be in cache, even after fanning occurs?
|
|
|
|
unsigned int tmp;
|
2023-10-07 12:17:39 +00:00
|
|
|
if ((tmp = iStampCnt - piCachingStamps[dp]) + 2 * piNumTriPtr[dp] <= mConfigCacheDepth) {
|
2015-05-19 03:57:13 +00:00
|
|
|
priority = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep best candidate
|
|
|
|
if (priority > max_priority) {
|
|
|
|
max_priority = priority;
|
|
|
|
ivdx = dp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// did we reach a dead end?
|
|
|
|
if (-1 == ivdx) {
|
|
|
|
// need to get a non-local vertex for which we have a good chance that it is still
|
|
|
|
// in the cache ...
|
|
|
|
while (!sDeadEndVStack.empty()) {
|
|
|
|
unsigned int iCachedIdx = sDeadEndVStack.top();
|
|
|
|
sDeadEndVStack.pop();
|
2023-10-07 12:17:39 +00:00
|
|
|
if (piNumTriPtr[iCachedIdx] > 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ivdx = iCachedIdx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-1 == ivdx) {
|
|
|
|
// well, there isn't such a vertex. Simply get the next vertex in input order and
|
|
|
|
// hope it is not too bad ...
|
2023-10-07 12:17:39 +00:00
|
|
|
while (ics < (int)pMesh->mNumVertices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++ics;
|
2023-10-07 12:17:39 +00:00
|
|
|
if (piNumTriPtr[ics] > 0) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ivdx = ics;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-10 21:26:00 +00:00
|
|
|
ai_real fACMR2 = 0.0f;
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!DefaultLogger::isNullLogger()) {
|
2023-10-07 12:17:39 +00:00
|
|
|
fACMR2 = static_cast<ai_real>(iCacheMisses / pMesh->mNumFaces);
|
|
|
|
const ai_real averageACMR = ((fACMR - fACMR2) / fACMR) * 100.f;
|
2015-05-19 03:57:13 +00:00
|
|
|
// very intense verbose logging ... prepare for much text if there are many meshes
|
2023-10-07 12:17:39 +00:00
|
|
|
if (DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) {
|
|
|
|
ASSIMP_LOG_VERBOSE_DEBUG("Mesh ", meshNum, "| ACMR in: ", fACMR, " out: ", fACMR2, " | average ACMR ", averageACMR);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
fACMR2 *= pMesh->mNumFaces;
|
|
|
|
}
|
2023-10-07 12:17:39 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// sort the output index buffer back to the input array
|
2023-10-07 12:17:39 +00:00
|
|
|
piCSIter = piIBOutput.begin();
|
|
|
|
for (aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) {
|
2018-04-23 09:33:48 +00:00
|
|
|
unsigned nind = pcFace->mNumIndices;
|
2023-10-07 12:17:39 +00:00
|
|
|
unsigned *ind = pcFace->mIndices;
|
|
|
|
if (nind > 0)
|
|
|
|
ind[0] = *piCSIter++;
|
|
|
|
if (nind > 1)
|
|
|
|
ind[1] = *piCSIter++;
|
|
|
|
if (nind > 2)
|
|
|
|
ind[2] = *piCSIter++;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fACMR2;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
2023-10-07 12:17:39 +00:00
|
|
|
|
|
|
|
} // namespace Assimp
|