Skip to content

Commit

Permalink
lf
Browse files Browse the repository at this point in the history
  • Loading branch information
kzhsw committed Jul 23, 2024
1 parent 735d784 commit 3737bf1
Show file tree
Hide file tree
Showing 7 changed files with 1,267 additions and 1,263 deletions.
78 changes: 39 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
# Variables for paths
WASI_SDK_PATH = ~/wasi-sdk-22.0/bin
BINARYEN_PATH = ~/binaryen-version_112/bin

# Variables for flags
C_FLAGS = -DJS_PROGRESS=1 -DXA_DEBUG=0 -DXA_MULTITHREADED=0 -DXATLAS_C_API=1 -mnontrapping-fptoint \
-msign-ext -mbulk-memory -flto=full -ffast-math -ffp-contract=fast -fomit-frame-pointer \
-Wextra -Wall -DNDEBUG -Wextra -flto -fno-builtin -ffreestanding -fno-ident -nostartfiles
LD_FLAGS = -Wl,--no-export-dynamic,--compress-relocations,--Bstatic \
-Wl,--strip-debug,--gc-sections,--no-entry,--export-dynamic,--initial-memory=131072 \
-Wl,--export=xatlasCreate,--export=xatlasDestroy,--export=xatlasAddMesh,--export=xatlasAddUvMesh \
-Wl,--export=xatlasComputeCharts,--export=xatlasPackCharts,--export=xatlasGenerate,--export=xatlasMeshDeclInit \
-Wl,--export=xatlasUvMeshDeclInit,--export=xatlasChartOptionsInit,--export=xatlasPackOptionsInit \
-Wl,--export=malloc,--export=realloc,--export=free,--export=copy_uv

# Source files
SRC_FILES = copy_uv.c xatlas/source/xatlas/xatlas.cpp

# Targets
all: xatlas-dbg.wasm xatlas-opt.wasm

xatlas-dbg.wasm: $(SRC_FILES)
$(WASI_SDK_PATH)/clang $(C_FLAGS) -DJS_DEBUG=1 -Og $(SRC_FILES) $(LD_FLAGS) \
-Wl,--export=xatlasAddMeshJoin,--export=xatlasAddMeshErrorString,--export=xatlasProgressCategoryString \
-o xatlas-dbg.wasm

xatlas.wasm: $(SRC_FILES)
$(WASI_SDK_PATH)/clang $(C_FLAGS) -DNDEBUG -O3 -Ofast -Os $(SRC_FILES) $(LD_FLAGS) \
-Wl,--strip-all,-O3,--lto-O3,--lto-CGO3 \
-o xatlas.wasm

xatlas-opt.wasm: xatlas.wasm
$(BINARYEN_PATH)/wasm-opt -O3 -O4 -s --directize --vacuum --zero-filled-memory --enable-nontrapping-float-to-int --enable-bulk-memory --strip-debug --strip-producers --strip-dwarf \
-o xatlas-opt.wasm xatlas.wasm

clean:
rm -f xatlas-dbg.wasm xatlas.wasm xatlas-opt.wasm

.PHONY: all clean
# Variables for paths
WASI_SDK_PATH = ~/wasi-sdk-22.0/bin
BINARYEN_PATH = ~/binaryen-version_112/bin

# Variables for flags
C_FLAGS = -DJS_PROGRESS=1 -DXA_DEBUG=0 -DXA_MULTITHREADED=0 -DXATLAS_C_API=1 -mnontrapping-fptoint \
-msign-ext -mbulk-memory -flto=full -ffast-math -ffp-contract=fast -fomit-frame-pointer \
-Wextra -Wall -DNDEBUG -Wextra -flto -fno-builtin -ffreestanding -fno-ident -nostartfiles
LD_FLAGS = -Wl,--no-export-dynamic,--compress-relocations,--Bstatic \
-Wl,--strip-debug,--gc-sections,--no-entry,--export-dynamic,--initial-memory=131072 \
-Wl,--export=xatlasCreate,--export=xatlasDestroy,--export=xatlasAddMesh,--export=xatlasAddUvMesh \
-Wl,--export=xatlasComputeCharts,--export=xatlasPackCharts,--export=xatlasGenerate,--export=xatlasMeshDeclInit \
-Wl,--export=xatlasUvMeshDeclInit,--export=xatlasChartOptionsInit,--export=xatlasPackOptionsInit \
-Wl,--export=malloc,--export=realloc,--export=free,--export=copy_uv

# Source files
SRC_FILES = copy_uv.c xatlas/source/xatlas/xatlas.cpp

# Targets
all: xatlas-dbg.wasm xatlas-opt.wasm

xatlas-dbg.wasm: $(SRC_FILES)
$(WASI_SDK_PATH)/clang $(C_FLAGS) -DJS_DEBUG=1 -Og $(SRC_FILES) $(LD_FLAGS) \
-Wl,--export=xatlasAddMeshJoin,--export=xatlasAddMeshErrorString,--export=xatlasProgressCategoryString \
-o xatlas-dbg.wasm

xatlas.wasm: $(SRC_FILES)
$(WASI_SDK_PATH)/clang $(C_FLAGS) -DNDEBUG -O3 -Ofast -Os $(SRC_FILES) $(LD_FLAGS) \
-Wl,--strip-all,-O3,--lto-O3,--lto-CGO3 \
-o xatlas.wasm

xatlas-opt.wasm: xatlas.wasm
$(BINARYEN_PATH)/wasm-opt -O3 -O4 -s --directize --vacuum --zero-filled-memory --enable-nontrapping-float-to-int --enable-bulk-memory --strip-debug --strip-producers --strip-dwarf \
-o xatlas-opt.wasm xatlas.wasm

clean:
rm -f xatlas-dbg.wasm xatlas.wasm xatlas-opt.wasm

.PHONY: all clean
36 changes: 18 additions & 18 deletions copy_uv.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "./xatlas/source/xatlas/xatlas_c.h"
#include <stdint.h>

uint32_t copy_uv(xatlasAtlas * atlas, xatlasMesh * mesh, void * output) {
const uint32_t vertex_count = mesh->vertexCount;
uint32_t * original_index = (uint32_t *) output;
float * uv = (float *) (original_index + vertex_count);
const float width = atlas->width;
const float height = atlas->height;

for (uint32_t i = 0; i < vertex_count; i++) {
const xatlasVertex * vertex = &mesh->vertexArray[i];
original_index[i] = vertex->xref;
uv[i * 2] = vertex->uv[0] / width;
uv[i * 2 + 1] = vertex->uv[1] / height;
}
return vertex_count;
}
#include "./xatlas/source/xatlas/xatlas_c.h"
#include <stdint.h>

uint32_t copy_uv(xatlasAtlas * atlas, xatlasMesh * mesh, void * output) {
const uint32_t vertex_count = mesh->vertexCount;
uint32_t * original_index = (uint32_t *) output;
float * uv = (float *) (original_index + vertex_count);
const float width = atlas->width;
const float height = atlas->height;

for (uint32_t i = 0; i < vertex_count; i++) {
const xatlasVertex * vertex = &mesh->vertexArray[i];
original_index[i] = vertex->xref;
uv[i * 2] = vertex->uv[0] / width;
uv[i * 2 + 1] = vertex->uv[1] / height;
}
return vertex_count;
}
Loading

0 comments on commit 3737bf1

Please sign in to comment.