Update meshoptimizer to version 0.18
This commit is contained in:
committed by
Philip Rideout
parent
117ae1d648
commit
b151afe567
@@ -2,7 +2,6 @@
|
||||
#include "meshoptimizer.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
// This work is based on:
|
||||
@@ -14,13 +13,23 @@ namespace meshopt
|
||||
const size_t kCacheSizeMax = 16;
|
||||
const size_t kValenceMax = 8;
|
||||
|
||||
static const float kVertexScoreTableCache[1 + kCacheSizeMax] = {
|
||||
0.f,
|
||||
0.792f, 0.767f, 0.764f, 0.956f, 0.827f, 0.751f, 0.820f, 0.864f, 0.738f, 0.788f, 0.642f, 0.646f, 0.165f, 0.654f, 0.545f, 0.284f};
|
||||
struct VertexScoreTable
|
||||
{
|
||||
float cache[1 + kCacheSizeMax];
|
||||
float live[1 + kValenceMax];
|
||||
};
|
||||
|
||||
static const float kVertexScoreTableLive[1 + kValenceMax] = {
|
||||
0.f,
|
||||
0.994f, 0.721f, 0.479f, 0.423f, 0.174f, 0.080f, 0.249f, 0.056f};
|
||||
// Tuned to minimize the ACMR of a GPU that has a cache profile similar to NVidia and AMD
|
||||
static const VertexScoreTable kVertexScoreTable = {
|
||||
{0.f, 0.779f, 0.791f, 0.789f, 0.981f, 0.843f, 0.726f, 0.847f, 0.882f, 0.867f, 0.799f, 0.642f, 0.613f, 0.600f, 0.568f, 0.372f, 0.234f},
|
||||
{0.f, 0.995f, 0.713f, 0.450f, 0.404f, 0.059f, 0.005f, 0.147f, 0.006f},
|
||||
};
|
||||
|
||||
// Tuned to minimize the encoded index buffer size
|
||||
static const VertexScoreTable kVertexScoreTableStrip = {
|
||||
{0.f, 1.000f, 1.000f, 1.000f, 0.453f, 0.561f, 0.490f, 0.459f, 0.179f, 0.526f, 0.000f, 0.227f, 0.184f, 0.490f, 0.112f, 0.050f, 0.131f},
|
||||
{0.f, 0.956f, 0.786f, 0.577f, 0.558f, 0.618f, 0.549f, 0.499f, 0.489f},
|
||||
};
|
||||
|
||||
struct TriangleAdjacency
|
||||
{
|
||||
@@ -132,13 +141,13 @@ static unsigned int getNextVertexNeighbour(const unsigned int* next_candidates_b
|
||||
return best_candidate;
|
||||
}
|
||||
|
||||
static float vertexScore(int cache_position, unsigned int live_triangles)
|
||||
static float vertexScore(const VertexScoreTable* table, int cache_position, unsigned int live_triangles)
|
||||
{
|
||||
assert(cache_position >= -1 && cache_position < int(kCacheSizeMax));
|
||||
|
||||
unsigned int live_triangles_clamped = live_triangles < kValenceMax ? live_triangles : kValenceMax;
|
||||
|
||||
return kVertexScoreTableCache[1 + cache_position] + kVertexScoreTableLive[live_triangles_clamped];
|
||||
return table->cache[1 + cache_position] + table->live[live_triangles_clamped];
|
||||
}
|
||||
|
||||
static unsigned int getNextTriangleDeadEnd(unsigned int& input_cursor, const unsigned char* emitted_flags, size_t face_count)
|
||||
@@ -157,7 +166,7 @@ static unsigned int getNextTriangleDeadEnd(unsigned int& input_cursor, const uns
|
||||
|
||||
} // namespace meshopt
|
||||
|
||||
void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count)
|
||||
void meshopt_optimizeVertexCacheTable(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, const meshopt::VertexScoreTable* table)
|
||||
{
|
||||
using namespace meshopt;
|
||||
|
||||
@@ -198,7 +207,7 @@ void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int*
|
||||
float* vertex_scores = allocator.allocate<float>(vertex_count);
|
||||
|
||||
for (size_t i = 0; i < vertex_count; ++i)
|
||||
vertex_scores[i] = vertexScore(-1, live_triangles[i]);
|
||||
vertex_scores[i] = vertexScore(table, -1, live_triangles[i]);
|
||||
|
||||
// compute triangle scores
|
||||
float* triangle_scores = allocator.allocate<float>(face_count);
|
||||
@@ -299,7 +308,7 @@ void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int*
|
||||
int cache_position = i >= cache_size ? -1 : int(i);
|
||||
|
||||
// update vertex score
|
||||
float score = vertexScore(cache_position, live_triangles[index]);
|
||||
float score = vertexScore(table, cache_position, live_triangles[index]);
|
||||
float score_diff = score - vertex_scores[index];
|
||||
|
||||
vertex_scores[index] = score;
|
||||
@@ -339,6 +348,16 @@ void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int*
|
||||
assert(output_triangle == face_count);
|
||||
}
|
||||
|
||||
void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count)
|
||||
{
|
||||
meshopt_optimizeVertexCacheTable(destination, indices, index_count, vertex_count, &meshopt::kVertexScoreTable);
|
||||
}
|
||||
|
||||
void meshopt_optimizeVertexCacheStrip(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count)
|
||||
{
|
||||
meshopt_optimizeVertexCacheTable(destination, indices, index_count, vertex_count, &meshopt::kVertexScoreTableStrip);
|
||||
}
|
||||
|
||||
void meshopt_optimizeVertexCacheFifo(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, unsigned int cache_size)
|
||||
{
|
||||
using namespace meshopt;
|
||||
|
||||
Reference in New Issue
Block a user