mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
wasm: remove ASYNCIFY to reduce binary size
The binary size recently increased due to the ASYNCIFY option, which was required for WebGPU initialization. To prevent unnecessary binary size growth, ThorVG will no longer depend on asynchronous processes such as `emscripten_sleep` (ASYNCIFY or JSPI). As a result, the combined WASM binary size has been significantly reduced to less than 1MB. Size comparison: 1559KB → 998KB (-36%)
This commit is contained in:
parent
2e84315857
commit
5d617c0821
3 changed files with 18 additions and 5 deletions
|
@ -12,7 +12,7 @@ exe_suffix = 'js'
|
||||||
|
|
||||||
[built-in options]
|
[built-in options]
|
||||||
cpp_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions']
|
cpp_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions']
|
||||||
cpp_link_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions', '--bind', '-sWASM=1', '-sALLOW_MEMORY_GROWTH=1', '-sEXPORT_ES6=1', '-sFORCE_FILESYSTEM=1', '-sMODULARIZE=1', '-sEXPORTED_RUNTIME_METHODS=FS', '-sUSE_WEBGPU=1', '-sASYNCIFY=1', '-sSTACK_SIZE=2MB', '-sMAX_WEBGL_VERSION=2', '-sFULL_ES3']
|
cpp_link_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions', '--bind', '-sWASM=1', '-sALLOW_MEMORY_GROWTH=1', '-sEXPORT_ES6=1', '-sFORCE_FILESYSTEM=1', '-sMODULARIZE=1', '-sEXPORTED_RUNTIME_METHODS=FS', '-sUSE_WEBGPU=1', '-sSTACK_SIZE=2MB', '-sMAX_WEBGL_VERSION=2', '-sFULL_ES3']
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'emscripten'
|
system = 'emscripten'
|
||||||
|
|
|
@ -12,7 +12,7 @@ exe_suffix = 'js'
|
||||||
|
|
||||||
[built-in options]
|
[built-in options]
|
||||||
cpp_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions']
|
cpp_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions']
|
||||||
cpp_link_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions', '--bind', '-sWASM=1', '-sALLOW_MEMORY_GROWTH=1', '-sEXPORT_ES6=1', '-sFORCE_FILESYSTEM=1', '-sMODULARIZE=1', '-sEXPORTED_RUNTIME_METHODS=FS', '-sUSE_WEBGPU=1', '-sASYNCIFY=1', '-sSTACK_SIZE=2MB']
|
cpp_link_args = ['-Wshift-negative-value', '-flto', '-Os', '-fno-exceptions', '--bind', '-sWASM=1', '-sALLOW_MEMORY_GROWTH=1', '-sEXPORT_ES6=1', '-sFORCE_FILESYSTEM=1', '-sMODULARIZE=1', '-sEXPORTED_RUNTIME_METHODS=FS', '-sUSE_WEBGPU=1', '-sSTACK_SIZE=2MB']
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = 'emscripten'
|
system = 'emscripten'
|
||||||
|
|
|
@ -41,9 +41,12 @@ static const char* NoError = "None";
|
||||||
static WGPUInstance instance{};
|
static WGPUInstance instance{};
|
||||||
static WGPUAdapter adapter{};
|
static WGPUAdapter adapter{};
|
||||||
static WGPUDevice device{};
|
static WGPUDevice device{};
|
||||||
|
static bool adapterRequested = false;
|
||||||
|
static bool deviceRequested = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void init()
|
// 0: success, 1: fail, 2: wait for async request
|
||||||
|
int init()
|
||||||
{
|
{
|
||||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
#ifdef THORVG_WG_RASTER_SUPPORT
|
||||||
//Init WebGPU
|
//Init WebGPU
|
||||||
|
@ -51,22 +54,32 @@ void init()
|
||||||
|
|
||||||
// request adapter
|
// request adapter
|
||||||
if (!adapter) {
|
if (!adapter) {
|
||||||
|
if (adapterRequested) return 2;
|
||||||
|
|
||||||
const WGPURequestAdapterOptions requestAdapterOptions { .nextInChain = nullptr, .powerPreference = WGPUPowerPreference_HighPerformance, .forceFallbackAdapter = false };
|
const WGPURequestAdapterOptions requestAdapterOptions { .nextInChain = nullptr, .powerPreference = WGPUPowerPreference_HighPerformance, .forceFallbackAdapter = false };
|
||||||
auto onAdapterRequestEnded = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, char const * message, void * pUserData) { *((WGPUAdapter*)pUserData) = adapter; };
|
auto onAdapterRequestEnded = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, char const * message, void * pUserData) { *((WGPUAdapter*)pUserData) = adapter; };
|
||||||
wgpuInstanceRequestAdapter(instance, &requestAdapterOptions, onAdapterRequestEnded, &adapter);
|
wgpuInstanceRequestAdapter(instance, &requestAdapterOptions, onAdapterRequestEnded, &adapter);
|
||||||
while (!adapter) emscripten_sleep(10);
|
|
||||||
|
adapterRequested = true;
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// request device
|
// request device
|
||||||
|
if (deviceRequested) return device == nullptr ? 2 : 0;
|
||||||
|
|
||||||
WGPUFeatureName featureNames[32]{};
|
WGPUFeatureName featureNames[32]{};
|
||||||
size_t featuresCount = wgpuAdapterEnumerateFeatures(adapter, featureNames);
|
size_t featuresCount = wgpuAdapterEnumerateFeatures(adapter, featureNames);
|
||||||
if (!device) {
|
if (!device) {
|
||||||
const WGPUDeviceDescriptor deviceDesc { .nextInChain = nullptr, .label = "The device", .requiredFeatureCount = featuresCount, .requiredFeatures = featureNames };
|
const WGPUDeviceDescriptor deviceDesc { .nextInChain = nullptr, .label = "The device", .requiredFeatureCount = featuresCount, .requiredFeatures = featureNames };
|
||||||
auto onDeviceRequestEnded = [](WGPURequestDeviceStatus status, WGPUDevice device, char const * message, void * pUserData) { *((WGPUDevice*)pUserData) = device; };
|
auto onDeviceRequestEnded = [](WGPURequestDeviceStatus status, WGPUDevice device, char const * message, void * pUserData) { *((WGPUDevice*)pUserData) = device; };
|
||||||
wgpuAdapterRequestDevice(adapter, &deviceDesc, onDeviceRequestEnded, &device);
|
wgpuAdapterRequestDevice(adapter, &deviceDesc, onDeviceRequestEnded, &device);
|
||||||
while (!device) emscripten_sleep(10);
|
|
||||||
|
deviceRequested = true;
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void term()
|
void term()
|
||||||
|
|
Loading…
Add table
Reference in a new issue