wasm: Use -Oz instead of -Os hoping better reduced code size.

wasm: lower stack size(4MB -> 2MB)
This commit is contained in:
Syoyo Fujita
2025-05-20 09:26:34 +09:00
parent 95dc3aeeeb
commit e3eae462bc
3 changed files with 122 additions and 19 deletions

View File

@@ -18,6 +18,11 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake)
#list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake/sanitizers)
#find_package(Sanitizers) # Address sanitizer (-DSANITIZE_ADDRESS=ON)
if (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
# Use Oz to reduce size further than Os
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Oz -DNODEBUG")
endif()
# [tinyusdz]
add_subdirectory(../ tinyusdz)
@@ -53,8 +58,8 @@ if (EMSCRIPTEN)
endif()
# TODO: Adjust memory size.
# 4MB stack
set_target_properties(${BUILD_TARGET} PROPERTIES LINK_FLAGS "-sENVIRONMENT='web,worker' -sSTACK_SIZE=4000000 -sASSERTIONS -s ALLOW_MEMORY_GROWTH=1 -sMODULARIZE=1 -sEXPORT_ES6 -sINVOKE_RUN=0 --bind")
# 2MB stack
set_target_properties(${BUILD_TARGET} PROPERTIES LINK_FLAGS "-sENVIRONMENT='web,worker' -sSTACK_SIZE=2000000 -sASSERTIONS -s ALLOW_MEMORY_GROWTH=1 -sMODULARIZE=1 -sEXPORT_ES6 -sINVOKE_RUN=0 --bind")
# ENVIRONMENT=web
# SINGLE_FILE=1

View File

@@ -1,7 +1,11 @@
// SPDX-License-Identifier: Apache 2.0
// Copyright 2024-Present Light Transport Entertainment, Inc.
//
#include <emscripten/bind.h>
#include <vector>
#include "external/fast_float/include/fast_float/bigint.h"
#include "tinyusdz.hh"
#include "tydra/render-data.hh"
#include "tydra/scene-access.hh"
@@ -52,6 +56,8 @@ bool ToRGBA(const std::vector<uint8_t> &src, int channels,
///
/// Simple C++ wrapper class for Emscripten
///
/// TODO: Provide Three.js GLTFLoader like interface.
///
class TinyUSDZLoader {
public:
///
@@ -108,6 +114,21 @@ class TinyUSDZLoader {
}
~TinyUSDZLoader() {}
emscripten::val loadAsync(const std::string &binary) {
tinyusdz::Layer layer;
// TODO:
return emscripten::val::null();
}
emscripten::val loadAsLayer(const std::string &binary) {
tinyusdz::Layer layer;
// TODO:
return emscripten::val::null();
}
int numMeshes() const {
return render_scene_.meshes.size();
}
@@ -127,31 +148,95 @@ class TinyUSDZLoader {
const auto &m = render_scene_.materials[mat_id];
// UsdPreviewSurface like shader param
// [ ] diffuseColor : color3f or texture
// [ ] emissiveColor : color3f or texture
// [ ] useSpecularWorkflow : bool
// [x] diffuseColor : color3f or texture
// [x] emissiveColor : color3f or texture
// [x] useSpecularWorkflow : bool
// * SpecularWorkflow
// [ ] specularColor : color3f or texture
// [x] specularColor : color3f or texture
// * MetalnessWorkflow
// [ ] metallic : float or texture
// [ ] roughness : float or texture
// [ ] clearcoat : float or texture
// [ ] clearcoatRoughness : float or texture
// [ ] opacity : float or texture
// [x] metallic : float or texture
// [x] roughness : float or texture
// [x] clearcoat : float or texture
// [x] clearcoatRoughness : float or texture
// [x] opacity : float or texture
// [ ] opacityMode(from 2.6) : transparent or presence
// [ ] opacityThreshold : float or texture
// [ ] ior : float or texture
// [ ] normal : normal3f or texture
// [ ] displacement : float or texture
// [ ] occlusion : float or texture
// [x] opacityThreshold : float or texture
// [x] ior : float or texture
// [x] normal : normal3f or texture
// [x] displacement : float or texture
// [x] occlusion : float or texture
mat.set("diffuseColor", m.surfaceShader.diffuseColor);
mat.set("diffuseColor", m.surfaceShader.diffuseColor.value);
if (m.surfaceShader.diffuseColor.is_texture()) {
mat.set("diffuseColorTextureId", m.surfaceShader.diffuseColor.texture_id);
}
mat.set("emissiveColor", m.surfaceShader.emissiveColor);
mat.set("occlusion", m.surfaceShader.occlusion);
mat.set("emissiveColor", m.surfaceShader.emissiveColor.value);
if (m.surfaceShader.emissiveColor.is_texture()) {
mat.set("emissiveColorTextureId", m.surfaceShader.emissiveColor.texture_id);
}
mat.set("useSpecularWorkflow", m.surfaceShader.useSpecularWorkflow);
if (m.surfaceShader.useSpecularWorkflow) {
mat.set("specularColor", m.surfaceShader.specularColor.value);
if (m.surfaceShader.specularColor.is_texture()) {
mat.set("specularColorTextureId", m.surfaceShader.specularColor.texture_id);
}
} else {
mat.set("metallic", m.surfaceShader.metallic.value);
if (m.surfaceShader.metallic.is_texture()) {
mat.set("metallicTextureId", m.surfaceShader.metallic.texture_id);
}
}
mat.set("roughness", m.surfaceShader.roughness.value);
if (m.surfaceShader.roughness.is_texture()) {
mat.set("roughnessTextureId", m.surfaceShader.roughness.texture_id);
}
mat.set("cleacoat", m.surfaceShader.clearcoat.value);
if (m.surfaceShader.clearcoat.is_texture()) {
mat.set("cleacoatTextureId", m.surfaceShader.clearcoat.texture_id);
}
mat.set("clearcoatRoughness", m.surfaceShader.clearcoatRoughness.value);
if (m.surfaceShader.clearcoatRoughness.is_texture()) {
mat.set("clearcoatRoughnessTextureId", m.surfaceShader.clearcoatRoughness.texture_id);
}
mat.set("opacity", m.surfaceShader.opacity.value);
if (m.surfaceShader.opacity.is_texture()) {
mat.set("opacityTextureId", m.surfaceShader.opacity.texture_id);
}
// TODO
//mat.set("opacityMode", m.surfaceShader.opacityMode);
mat.set("opacityThreshold", m.surfaceShader.opacityThreshold.value);
if (m.surfaceShader.opacityThreshold.is_texture()) {
mat.set("opacityThresholdTextureId", m.surfaceShader.opacityThreshold.texture_id);
}
mat.set("ior", m.surfaceShader.ior.value);
if (m.surfaceShader.ior.is_texture()) {
mat.set("iorTextureId", m.surfaceShader.ior.texture_id);
}
mat.set("normal", m.surfaceShader.normal.value);
if (m.surfaceShader.normal.is_texture()) {
mat.set("normalTextureId", m.surfaceShader.normal.texture_id);
}
mat.set("displacement", m.surfaceShader.displacement.value);
if (m.surfaceShader.displacement.is_texture()) {
mat.set("displacementTextureId", m.surfaceShader.displacement.texture_id);
}
mat.set("occlusion", m.surfaceShader.occlusion.value);
if (m.surfaceShader.occlusion.is_texture()) {
mat.set("occlusionTextureId", m.surfaceShader.occlusion.texture_id);
}
return mat;
}
@@ -262,6 +347,15 @@ class TinyUSDZLoader {
tinyusdz::USDZAsset usdz_asset_;
};
///
/// USD composition
///
class TinyUSDZComposer
{
// TODO
};
// Register STL
EMSCRIPTEN_BINDINGS(stl_wrappters) {
register_vector<float>("VectorFloat");

4
web/bootstrap-linux.sh Executable file
View File

@@ -0,0 +1,4 @@
rm -rf build
mkdir build
emcmake cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_VERBOSE_MAKEFILE=1 -Bbuild