diff --git a/third_party/meshoptimizer/src/clusterizer.cpp b/third_party/meshoptimizer/src/clusterizer.cpp index 50525c36eb..52ed4660d0 100644 --- a/third_party/meshoptimizer/src/clusterizer.cpp +++ b/third_party/meshoptimizer/src/clusterizer.cpp @@ -310,9 +310,9 @@ meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t bounds.cone_cutoff = sqrtf(1 - mindp * mindp); // quantize axis & cutoff to 8-bit SNORM format - bounds.cone_axis_s8[0] = char(meshopt_quantizeSnorm(bounds.cone_axis[0], 8)); - bounds.cone_axis_s8[1] = char(meshopt_quantizeSnorm(bounds.cone_axis[1], 8)); - bounds.cone_axis_s8[2] = char(meshopt_quantizeSnorm(bounds.cone_axis[2], 8)); + bounds.cone_axis_s8[0] = (signed char)(meshopt_quantizeSnorm(bounds.cone_axis[0], 8)); + bounds.cone_axis_s8[1] = (signed char)(meshopt_quantizeSnorm(bounds.cone_axis[1], 8)); + bounds.cone_axis_s8[2] = (signed char)(meshopt_quantizeSnorm(bounds.cone_axis[2], 8)); // for the 8-bit test to be conservative, we need to adjust the cutoff by measuring the max. error float cone_axis_s8_e0 = fabsf(bounds.cone_axis_s8[0] / 127.f - bounds.cone_axis[0]); @@ -322,7 +322,7 @@ meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t // note that we need to round this up instead of rounding to nearest, hence +1 int cone_cutoff_s8 = int(127 * (bounds.cone_cutoff + cone_axis_s8_e0 + cone_axis_s8_e1 + cone_axis_s8_e2) + 1); - bounds.cone_cutoff_s8 = (cone_cutoff_s8 > 127) ? 127 : char(cone_cutoff_s8); + bounds.cone_cutoff_s8 = (cone_cutoff_s8 > 127) ? 127 : (signed char)(cone_cutoff_s8); return bounds; } diff --git a/third_party/meshoptimizer/src/indexgenerator.cpp b/third_party/meshoptimizer/src/indexgenerator.cpp index 55b8df3a20..485877837f 100644 --- a/third_party/meshoptimizer/src/indexgenerator.cpp +++ b/third_party/meshoptimizer/src/indexgenerator.cpp @@ -9,7 +9,7 @@ namespace meshopt struct VertexHasher { - const char* vertices; + const unsigned char* vertices; size_t vertex_size; size_t vertex_stride; @@ -20,7 +20,7 @@ struct VertexHasher const int r = 24; unsigned int h = 0; - const char* key = vertices + index * vertex_stride; + const unsigned char* key = vertices + index * vertex_stride; size_t len = vertex_size; while (len >= 4) @@ -97,7 +97,7 @@ size_t meshopt_generateVertexRemap(unsigned int* destination, const unsigned int memset(destination, -1, vertex_count * sizeof(unsigned int)); - VertexHasher hasher = {static_cast(vertices), vertex_size, vertex_size}; + VertexHasher hasher = {static_cast(vertices), vertex_size, vertex_size}; size_t table_size = hashBuckets(vertex_count); unsigned int* table = allocator.allocate(table_size); @@ -143,7 +143,7 @@ void meshopt_remapVertexBuffer(void* destination, const void* vertices, size_t v // support in-place remap if (destination == vertices) { - char* vertices_copy = allocator.allocate(vertex_count * vertex_size); + unsigned char* vertices_copy = allocator.allocate(vertex_count * vertex_size); memcpy(vertices_copy, vertices, vertex_count * vertex_size); vertices = vertices_copy; } @@ -154,7 +154,7 @@ void meshopt_remapVertexBuffer(void* destination, const void* vertices, size_t v { assert(remap[i] < vertex_count); - memcpy(static_cast(destination) + remap[i] * vertex_size, static_cast(vertices) + i * vertex_size, vertex_size); + memcpy(static_cast(destination) + remap[i] * vertex_size, static_cast(vertices) + i * vertex_size, vertex_size); } } } @@ -186,7 +186,7 @@ void meshopt_generateShadowIndexBuffer(unsigned int* destination, const unsigned unsigned int* remap = allocator.allocate(vertex_count); memset(remap, -1, vertex_count * sizeof(unsigned int)); - VertexHasher hasher = {static_cast(vertices), vertex_size, vertex_stride}; + VertexHasher hasher = {static_cast(vertices), vertex_size, vertex_stride}; size_t table_size = hashBuckets(vertex_count); unsigned int* table = allocator.allocate(table_size); diff --git a/third_party/meshoptimizer/src/meshoptimizer.h b/third_party/meshoptimizer/src/meshoptimizer.h index 20d2b4f9e0..82a5b5710b 100644 --- a/third_party/meshoptimizer/src/meshoptimizer.h +++ b/third_party/meshoptimizer/src/meshoptimizer.h @@ -11,7 +11,7 @@ #include #include -/* Version macro; major * 100 + minor * 10 + patch */ +/* Version macro; major * 1000 + minor * 10 + patch */ #define MESHOPTIMIZER_VERSION 90 /* If no API is defined, assume default */ @@ -256,8 +256,8 @@ struct meshopt_Bounds float cone_cutoff; /* = cos(angle/2) */ /* normal cone axis and cutoff, stored in 8-bit SNORM format; decode using x/127.0 */ - char cone_axis_s8[3]; - char cone_cutoff_s8; + signed char cone_axis_s8[3]; + signed char cone_cutoff_s8; }; /** diff --git a/third_party/meshoptimizer/src/simplifier.cpp b/third_party/meshoptimizer/src/simplifier.cpp index 64921d9508..d948a7ed8c 100644 --- a/third_party/meshoptimizer/src/simplifier.cpp +++ b/third_party/meshoptimizer/src/simplifier.cpp @@ -195,7 +195,7 @@ enum VertexKind // manifold vertices can collapse on anything except locked // border/seam vertices can only be collapsed onto border/seam respectively -const char kCanCollapse[Kind_Count][Kind_Count] = { +const unsigned char kCanCollapse[Kind_Count][Kind_Count] = { {1, 1, 1, 1}, {0, 1, 0, 0}, {0, 0, 1, 0}, @@ -205,7 +205,7 @@ const char kCanCollapse[Kind_Count][Kind_Count] = { // if a vertex is manifold or seam, adjoining edges are guaranteed to have an opposite edge // note that for seam edges, the opposite edge isn't present in the attribute-based topology // but is present if you consider a position-only mesh variant -const char kHasOpposite[Kind_Count][Kind_Count] = { +const unsigned char kHasOpposite[Kind_Count][Kind_Count] = { {1, 1, 1, 1}, {1, 0, 1, 0}, {1, 1, 1, 1}, diff --git a/third_party/meshoptimizer/src/vcacheoptimizer.cpp b/third_party/meshoptimizer/src/vcacheoptimizer.cpp index 335fe35c97..9af4c19f90 100644 --- a/third_party/meshoptimizer/src/vcacheoptimizer.cpp +++ b/third_party/meshoptimizer/src/vcacheoptimizer.cpp @@ -141,7 +141,7 @@ static float vertexScore(int cache_position, unsigned int live_triangles) return kVertexScoreTableCache[1 + cache_position] + kVertexScoreTableLive[live_triangles_clamped]; } -static unsigned int getNextTriangleDeadEnd(unsigned int& input_cursor, const char* emitted_flags, size_t face_count) +static unsigned int getNextTriangleDeadEnd(unsigned int& input_cursor, const unsigned char* emitted_flags, size_t face_count) { // input order while (input_cursor < face_count) @@ -191,7 +191,7 @@ void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int* memcpy(live_triangles, adjacency.counts, vertex_count * sizeof(unsigned int)); // emitted flags - char* emitted_flags = allocator.allocate(face_count); + unsigned char* emitted_flags = allocator.allocate(face_count); memset(emitted_flags, 0, face_count); // compute initial vertex scores @@ -379,7 +379,7 @@ void meshopt_optimizeVertexCacheFifo(unsigned int* destination, const unsigned i unsigned int dead_end_top = 0; // emitted flags - char* emitted_flags = allocator.allocate(face_count); + unsigned char* emitted_flags = allocator.allocate(face_count); memset(emitted_flags, 0, face_count); unsigned int current_vertex = 0; diff --git a/third_party/meshoptimizer/src/vertexcodec.cpp b/third_party/meshoptimizer/src/vertexcodec.cpp index d491fed613..a16e2b640f 100644 --- a/third_party/meshoptimizer/src/vertexcodec.cpp +++ b/third_party/meshoptimizer/src/vertexcodec.cpp @@ -4,10 +4,24 @@ #include #include -#ifdef __ARM_NEON__ +#if defined(__ARM_NEON__) || defined(__ARM_NEON) #define SIMD_NEON #endif +#if defined(__AVX__) || defined(__SSSE3__) +#define SIMD_SSE +#endif + +#if !defined(SIMD_SSE) && defined(WIN32) && (defined(_M_IX86) || defined(_M_X64)) +#define SIMD_SSE +#define SIMD_FALLBACK +#include +#endif + +#ifdef SIMD_SSE +#include +#endif + #ifdef SIMD_NEON #include #endif @@ -36,7 +50,7 @@ static size_t getVertexBlockSize(size_t vertex_size) inline unsigned char zigzag8(unsigned char v) { - return (char(v) >> 7) ^ (v << 1); + return ((signed char)(v) >> 7) ^ (v << 1); } inline unsigned char unzigzag8(unsigned char v) @@ -337,7 +351,7 @@ static bool decodeBytesGroupBuildTables() { int maski = (mask >> i) & 1; shuffle[i] = maski ? count : 0x80; - count += char(maski); + count += (unsigned char)(maski); } memcpy(kDecodeBytesGroupShuffle[mask], shuffle, 8); @@ -502,10 +516,10 @@ static void transpose8(uint8x16_t& x0, uint8x16_t& x1, uint8x16_t& x2, uint8x16_ uint16x8x2_t x01 = vzipq_u16(vreinterpretq_u16_u8(t01.val[0]), vreinterpretq_u16_u8(t23.val[0])); uint16x8x2_t x23 = vzipq_u16(vreinterpretq_u16_u8(t01.val[1]), vreinterpretq_u16_u8(t23.val[1])); - x0 = x01.val[0]; - x1 = x01.val[1]; - x2 = x23.val[0]; - x3 = x23.val[1]; + x0 = vreinterpretq_u8_u16(x01.val[0]); + x1 = vreinterpretq_u8_u16(x01.val[1]); + x2 = vreinterpretq_u8_u16(x23.val[0]); + x3 = vreinterpretq_u8_u16(x23.val[1]); } static uint8x16_t unzigzag8(uint8x16_t v) diff --git a/third_party/meshoptimizer/src/vfetchanalyzer.cpp b/third_party/meshoptimizer/src/vfetchanalyzer.cpp index 666d6ae4b0..51dca873f8 100644 --- a/third_party/meshoptimizer/src/vfetchanalyzer.cpp +++ b/third_party/meshoptimizer/src/vfetchanalyzer.cpp @@ -13,7 +13,7 @@ meshopt_VertexFetchStatistics meshopt_analyzeVertexFetch(const unsigned int* ind meshopt_VertexFetchStatistics result = {}; - char* vertex_visited = allocator.allocate(vertex_count); + unsigned char* vertex_visited = allocator.allocate(vertex_count); memset(vertex_visited, 0, vertex_count); const size_t kCacheLine = 64; diff --git a/third_party/meshoptimizer/src/vfetchoptimizer.cpp b/third_party/meshoptimizer/src/vfetchoptimizer.cpp index c2e16a5f7a..465d6df5ca 100644 --- a/third_party/meshoptimizer/src/vfetchoptimizer.cpp +++ b/third_party/meshoptimizer/src/vfetchoptimizer.cpp @@ -38,7 +38,7 @@ size_t meshopt_optimizeVertexFetch(void* destination, unsigned int* indices, siz // support in-place optimization if (destination == vertices) { - char* vertices_copy = allocator.allocate(vertex_count * vertex_size); + unsigned char* vertices_copy = allocator.allocate(vertex_count * vertex_size); memcpy(vertices_copy, vertices, vertex_count * vertex_size); vertices = vertices_copy; } @@ -59,7 +59,7 @@ size_t meshopt_optimizeVertexFetch(void* destination, unsigned int* indices, siz if (remap == ~0u) // vertex was not added to destination VB { // add vertex - memcpy(static_cast(destination) + next_vertex * vertex_size, static_cast(vertices) + index * vertex_size, vertex_size); + memcpy(static_cast(destination) + next_vertex * vertex_size, static_cast(vertices) + index * vertex_size, vertex_size); remap = next_vertex++; } diff --git a/third_party/meshoptimizer/tnt/README b/third_party/meshoptimizer/tnt/README index aae7436d61..8d2f27ea73 100644 --- a/third_party/meshoptimizer/tnt/README +++ b/third_party/meshoptimizer/tnt/README @@ -1,12 +1,19 @@ This folder was created as follows: -cd third_party -curl -L -O https://github.com/zeux/meshoptimizer/archive/0a816f5.zip -unzip 0a816f5.zip -mv meshoptimizer-* meshoptimizer -cd meshoptimizer -rm -rf demo tools -mv LICENSE.md LICENSE + cd third_party + curl -L -O https://github.com/zeux/meshoptimizer/archive/0a816f5.zip + unzip 0a816f5.zip + mv meshoptimizer-* meshoptimizer + cd meshoptimizer + rm -rf demo tools + mv LICENSE.md LICENSE Also removed lines 11 - 24 vertexcodec.cpp to disable SSE, which caused build issues with windows. + +To update the library, you can do this: + + curl -L -O https://github.com/zeux/meshoptimizer/archive/master.zip + unzip master.zip + cp -r meshoptimizer-master/src/ meshoptimizer/src/ + in vertexcodec.cpp, replace _MSC_VER with WIN32