mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Updated meshoptimizer.
This commit is contained in:
@@ -3,8 +3,12 @@ name: build
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
linux:
|
||||
runs-on: ubuntu-latest
|
||||
unix:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu, macos]
|
||||
name: ${{matrix.os}}
|
||||
runs-on: ${{matrix.os}}-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: make test
|
||||
@@ -18,27 +22,10 @@ jobs:
|
||||
make -j2 config=coverage test
|
||||
find . -type f -name '*.gcno' -exec gcov -p {} +
|
||||
sed -i -e "s/#####\(.*\)\(\/\/ unreachable.*\)/ -\1\2/" *.gcov
|
||||
bash <(curl -s https://codecov.io/bash) -f 'src#*.gcov' -X search -t ${{secrets.CODECOV_TOKEN}}
|
||||
bash <(curl -s https://codecov.io/bash) -f 'src#*.gcov' -X search -t ${{secrets.CODECOV_TOKEN}} -B ${{github.ref}}
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: gltfpack-linux
|
||||
path: gltfpack
|
||||
|
||||
macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: make test
|
||||
run: |
|
||||
make -j2 config=sanitize test
|
||||
make -j2 config=debug test
|
||||
make -j2 config=release test
|
||||
make -j2 config=release gltfpack
|
||||
- name: make iphone
|
||||
run: make -j2 config=iphone
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: gltfpack-macos
|
||||
name: gltfpack-${{matrix.os}}
|
||||
path: gltfpack
|
||||
|
||||
windows:
|
||||
|
||||
2
3rdparty/meshoptimizer/Makefile
vendored
2
3rdparty/meshoptimizer/Makefile
vendored
@@ -72,7 +72,7 @@ gltfpack: $(GLTFPACK_OBJECTS) $(LIBRARY)
|
||||
|
||||
js/meshopt_decoder.js: src/vertexcodec.cpp src/indexcodec.cpp
|
||||
@mkdir -p build
|
||||
emcc $(filter %.cpp,$^) -O3 -DNDEBUG -s EXPORTED_FUNCTIONS='["_meshopt_decodeVertexBuffer", "_meshopt_decodeIndexBuffer"]' -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=24576 -s TOTAL_MEMORY=65536 -o build/meshopt_decoder.wasm
|
||||
emcc $(filter %.cpp,$^) -O3 -DNDEBUG -s EXPORTED_FUNCTIONS='["_meshopt_decodeVertexBuffer", "_meshopt_decodeIndexBuffer", "_sbrk"]' -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=24576 -s TOTAL_MEMORY=65536 -o build/meshopt_decoder.wasm
|
||||
sed -i "s#\(var wasm = \)\".*\";#\\1\"$$(cat build/meshopt_decoder.wasm | base64 -w 0)\";#" $@
|
||||
|
||||
$(EXECUTABLE): $(DEMO_OBJECTS) $(LIBRARY)
|
||||
|
||||
103
3rdparty/meshoptimizer/demo/tests.cpp
vendored
103
3rdparty/meshoptimizer/demo/tests.cpp
vendored
@@ -1,6 +1,7 @@
|
||||
#include "../src/meshoptimizer.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -261,6 +262,100 @@ static void clusterBoundsDegenerate()
|
||||
assert(bounds2.center[2] - bounds2.radius <= 0 && bounds2.center[2] + bounds2.radius >= 1);
|
||||
}
|
||||
|
||||
static size_t allocCount;
|
||||
static size_t freeCount;
|
||||
|
||||
static void* customAlloc(size_t size)
|
||||
{
|
||||
allocCount++;
|
||||
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void customFree(void* ptr)
|
||||
{
|
||||
freeCount++;
|
||||
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static void customAllocator()
|
||||
{
|
||||
meshopt_setAllocator(customAlloc, customFree);
|
||||
|
||||
assert(allocCount == 0 && freeCount == 0);
|
||||
|
||||
float vb[] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
|
||||
unsigned int ib[] = {0, 1, 2};
|
||||
unsigned short ibs[] = {0, 1, 2};
|
||||
|
||||
// meshopt_computeClusterBounds doesn't allocate
|
||||
meshopt_computeClusterBounds(ib, 3, vb, 3, 12);
|
||||
assert(allocCount == 0 && freeCount == 0);
|
||||
|
||||
// ... unless IndexAdapter is used
|
||||
meshopt_computeClusterBounds(ibs, 3, vb, 3, 12);
|
||||
assert(allocCount == 1 && freeCount == 1);
|
||||
|
||||
// meshopt_optimizeVertexFetch allocates internal remap table and temporary storage for in-place remaps
|
||||
meshopt_optimizeVertexFetch(vb, ib, 3, vb, 3, 12);
|
||||
assert(allocCount == 3 && freeCount == 3);
|
||||
|
||||
// ... plus one for IndexAdapter
|
||||
meshopt_optimizeVertexFetch(vb, ibs, 3, vb, 3, 12);
|
||||
assert(allocCount == 6 && freeCount == 6);
|
||||
|
||||
meshopt_setAllocator(operator new, operator delete);
|
||||
|
||||
// customAlloc & customFree should not get called anymore
|
||||
meshopt_optimizeVertexFetch(vb, ib, 3, vb, 3, 12);
|
||||
assert(allocCount == 6 && freeCount == 6);
|
||||
}
|
||||
|
||||
static void emptyMesh()
|
||||
{
|
||||
meshopt_optimizeVertexCache(0, 0, 0, 0);
|
||||
meshopt_optimizeVertexCacheFifo(0, 0, 0, 0, 16);
|
||||
meshopt_optimizeOverdraw(0, 0, 0, 0, 0, 12, 1.f);
|
||||
}
|
||||
|
||||
static void simplifyStuck()
|
||||
{
|
||||
// tetrahedron can't be simplified due to collapse error restrictions
|
||||
float vb1[] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1};
|
||||
unsigned int ib1[] = {0, 1, 2, 0, 2, 3, 0, 3, 1, 2, 1, 3};
|
||||
|
||||
assert(meshopt_simplify(ib1, ib1, 12, vb1, 4, 12, 6, 1e-3f) == 12);
|
||||
|
||||
// 5-vertex strip can't be simplified due to topology restriction since middle triangle has flipped winding
|
||||
float vb2[] = {0, 0, 0, 1, 0, 0, 2, 0, 0, 0.5f, 1, 0, 1.5f, 1, 0};
|
||||
unsigned int ib2[] = {0, 1, 3, 3, 1, 4, 1, 2, 4}; // ok
|
||||
unsigned int ib3[] = {0, 1, 3, 1, 3, 4, 1, 2, 4}; // flipped
|
||||
|
||||
assert(meshopt_simplify(ib2, ib2, 9, vb2, 5, 12, 6, 1e-3f) == 6);
|
||||
assert(meshopt_simplify(ib3, ib3, 9, vb2, 5, 12, 6, 1e-3f) == 9);
|
||||
}
|
||||
|
||||
static void simplifySloppyStuck()
|
||||
{
|
||||
const float vb[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
const unsigned int ib[] = {0, 1, 2, 0, 1, 2};
|
||||
|
||||
// simplifying down to 0 triangles results in 0 immediately
|
||||
assert(meshopt_simplifySloppy(0, ib, 3, vb, 3, 12, 0) == 0);
|
||||
|
||||
// simplifying down to 2 triangles given that all triangles are degenerate results in 0 as well
|
||||
assert(meshopt_simplifySloppy(0, ib, 6, vb, 3, 12, 6) == 0);
|
||||
}
|
||||
|
||||
static void simplifyPointsStuck()
|
||||
{
|
||||
const float vb[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
// simplifying down to 0 points results in 0 immediately
|
||||
assert(meshopt_simplifyPoints(0, vb, 3, 12, 0) == 0);
|
||||
}
|
||||
|
||||
void runTests()
|
||||
{
|
||||
decodeIndexV0();
|
||||
@@ -277,4 +372,12 @@ void runTests()
|
||||
decodeVertexRejectMalformedHeaders();
|
||||
|
||||
clusterBoundsDegenerate();
|
||||
|
||||
customAllocator();
|
||||
|
||||
emptyMesh();
|
||||
|
||||
simplifyStuck();
|
||||
simplifySloppyStuck();
|
||||
simplifyPointsStuck();
|
||||
}
|
||||
|
||||
55
3rdparty/meshoptimizer/js/meshopt_decoder.js
vendored
55
3rdparty/meshoptimizer/js/meshopt_decoder.js
vendored
File diff suppressed because one or more lines are too long
3
3rdparty/meshoptimizer/src/indexcodec.cpp
vendored
3
3rdparty/meshoptimizer/src/indexcodec.cpp
vendored
@@ -161,9 +161,6 @@ static void writeTriangle(void* destination, size_t offset, size_t index_size, u
|
||||
static_cast<unsigned short*>(destination)[offset + 2] = (unsigned short)(c);
|
||||
}
|
||||
else
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (index_size == 4) // work around Edge (ChakraCore) bug - without this compiler assumes index_size==2
|
||||
#endif
|
||||
{
|
||||
static_cast<unsigned int*>(destination)[offset + 0] = a;
|
||||
static_cast<unsigned int*>(destination)[offset + 1] = b;
|
||||
|
||||
3
3rdparty/meshoptimizer/src/simplifier.cpp
vendored
3
3rdparty/meshoptimizer/src/simplifier.cpp
vendored
@@ -1443,6 +1443,9 @@ size_t meshopt_simplifyPoints(unsigned int* destination, const float* vertex_pos
|
||||
|
||||
size_t target_cell_count = target_vertex_count;
|
||||
|
||||
if (target_cell_count == 0)
|
||||
return 0;
|
||||
|
||||
meshopt_Allocator allocator;
|
||||
|
||||
Vector3* vertex_positions = allocator.allocate<Vector3>(vertex_count);
|
||||
|
||||
6
3rdparty/meshoptimizer/src/vertexcodec.cpp
vendored
6
3rdparty/meshoptimizer/src/vertexcodec.cpp
vendored
@@ -309,7 +309,7 @@ static const unsigned char* decodeBytesGroup(const unsigned char* data, unsigned
|
||||
memcpy(buffer, data, kByteGroupSize);
|
||||
return data + kByteGroupSize;
|
||||
default:
|
||||
assert(!"Unexpected bit length"); // This can never happen since bitslog2 is a 2-bit value
|
||||
assert(!"Unexpected bit length"); // unreachable since bitslog2 is a 2-bit value
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
|
||||
}
|
||||
|
||||
default:
|
||||
assert(!"Unexpected bit length"); // This can never happen since bitslog2 is a 2-bit value
|
||||
assert(!"Unexpected bit length"); // unreachable since bitslog2 is a 2-bit value
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -649,7 +649,7 @@ static const unsigned char* decodeBytesGroupSimd(const unsigned char* data, unsi
|
||||
}
|
||||
|
||||
default:
|
||||
assert(!"Unexpected bit length"); // This can never happen since bitslog2 is a 2-bit value
|
||||
assert(!"Unexpected bit length"); // unreachable since bitslog2 is a 2-bit value
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user