Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add's native support for meshoptimizer #264

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmarks/meshoptimizer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/meshoptimizer
21 changes: 21 additions & 0 deletions benchmarks/meshoptimizer/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND="noninteractive" TZ="America"
RUN apt update && apt-get install -y --no-install-recommends wget build-essential git ca-certificates

# Install clang
RUN apt-get install -y --no-install-recommends clang

# Copy in the `src` directory.
ENV SRC=/usr/src/meshoptimizer/
WORKDIR $SRC
COPY sightglass.h sightglass.native.patch ./
COPY build-native.sh .
COPY libengine.so /usr/lib/

# Compile each of the benchmarks into the `/benchmark` directory.
RUN ./build-native.sh

# We copy the shared libraries to the `/benchmark` directory, where the client
# expects it.
WORKDIR /benchmark
RUN cp $SRC/*so .
15 changes: 15 additions & 0 deletions benchmarks/meshoptimizer/build-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# Build all of the shootout benchmarks as native shared libraries (Linux-only).
#
# Usage: ./build-native.sh

(set -x);
(rm -r -f meshoptimizer);
(git clone --recurse-submodules https://github.com/zeux/meshoptimizer.git);
(cd meshoptimizer; git reset --hard f734fd572aed5bf76e84d9ed62ca6f4f6c47d84e; cd -);
(cp sightglass.h sightglass.native.patch meshoptimizer/);
(cd meshoptimizer; patch -Np1 -i ./sightglass.native.patch; cd -);
(cd meshoptimizer; CXX=/usr/bin/clang++ make codecbench-simd.so ; cd -);
(set +x);

111 changes: 111 additions & 0 deletions benchmarks/meshoptimizer/sightglass.native.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
diff --git a/Makefile b/Makefile
index 6697c13..26e637f 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,9 @@ LIBRARY=$(BUILD)/libmeshoptimizer.a
DEMO=$(BUILD)/meshoptimizer

CFLAGS=-g -Wall -Wextra -Werror -std=c89
-CXXFLAGS=-g -Wall -Wextra -Wshadow -Wno-missing-field-initializers -Werror -std=c++98
+CXXFLAGS=-O3 -Wall -Wextra -Wshadow -Wno-missing-field-initializers -Werror -std=c++17 -fPIC
+CXXFLAGS_SIGHTGLASS=-O3 -Wall -Wextra -Wshadow -Wno-missing-field-initializers \
+ -std=c++17 -Dmain=native_entry -fno-exceptions -fPIC -I. -L../../../engines/native/ -shared
LDFLAGS=

$(GLTFPACK_OBJECTS): CXXFLAGS+=-std=c++11
@@ -167,6 +169,9 @@ codecbench.wasm: tools/codecbench.cpp ${LIBRARY_SOURCES}
codecbench-simd.wasm: tools/codecbench.cpp ${LIBRARY_SOURCES}
$(WASMCC) $^ -fno-exceptions --target=wasm32-wasi --sysroot=$(WASIROOT) -lc++ -lc++abi -O3 -g -DNDEBUG -msimd128 -o $@

+codecbench-simd.so: $(LIBRARY_OBJECTS)
+ $(CXX) $^ $(CXXFLAGS_SIGHTGLASS) $(LDFLAGS) tools/codecbench.cpp -o ../codecbench-simd.so -lengine
+
codecfuzz: tools/codecfuzz.cpp src/vertexcodec.cpp src/indexcodec.cpp
$(CXX) $^ -fsanitize=fuzzer,address,undefined -O1 -g -o $@

diff --git a/tools/codecbench.cpp b/tools/codecbench.cpp
index 350cb9c..f06bcff 100644
--- a/tools/codecbench.cpp
+++ b/tools/codecbench.cpp
@@ -1,4 +1,5 @@
#include "../src/meshoptimizer.h"
+#include "../sightglass.h"

#include <vector>

@@ -161,15 +162,12 @@ void benchFilters(size_t count, double& besto8, double& besto12, double& bestq12
}
}

-int main(int argc, char** argv)
+extern "C" {
+int main()
{
meshopt_encodeIndexVersion(1);

- bool verbose = false;
-
- for (int i = 1; i < argc; ++i)
- if (strcmp(argv[i], "-v") == 0)
- verbose = true;
+ bool verbose = true;

const int N = 1000;

@@ -212,13 +210,21 @@ int main(int argc, char** argv)
}
}

+ bench_start();
+
double bestvd = 0, bestid = 0;
benchCodecs(vertices, indices, bestvd, bestid, verbose);

double besto8 = 0, besto12 = 0, bestq12 = 0, bestexp = 0;
benchFilters(8 * N * N, besto8, besto12, bestq12, bestexp, verbose);

+ bench_end();
+
printf("Algorithm :\tvtx\tidx\toct8\toct12\tquat12\texp\n");
- printf("Score (GB/s):\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",
- bestvd, bestid, besto8, besto12, bestq12, bestexp);
+ if (verbose)
+ printf("Score (GB/s):\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",
+ bestvd, bestid, besto8, besto12, bestq12, bestexp);
+
+ return 0;
}
+}
\ No newline at end of file
diff --git a/sightglass.h b/sightglass.h
index a767e9e..f12c956 100644
--- a/sightglass.h
+++ b/sightglass.h
@@ -8,7 +8,13 @@
*/
__attribute__((import_module("bench")))
__attribute__((import_name("start")))
+#ifdef __cplusplus
+extern "C" {
+#endif
void bench_start();
+#ifdef __cplusplus
+}
+#endif

/**
* Call this function to indicate that recording should end. This call should be placed immediately
@@ -17,7 +23,13 @@ void bench_start();
*/
__attribute__((import_module("bench")))
__attribute__((import_name("end")))
+#ifdef __cplusplus
+extern "C" {
+#endif
jlb6740 marked this conversation as resolved.
Show resolved Hide resolved
void bench_end();
+#ifdef __cplusplus
+}
+#endif

/**
* Call this function to prevent certain compiler-related optimizations related to knowing the value
Loading