wasm: move user configurable settings

Both INITIAL_MEMORY and PTHREAD_POOL_SIZE are settings users can
change, they are not interface settings.

Fixes: QTBUG-100693
Pick-to: 6.3 6.2
Change-Id: Ie1547c7f52c9fe109a313260616705728024b6b8
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: David Skoland <david.skoland@qt.io>
This commit is contained in:
Lorn Potter 2022-02-14 09:28:51 +10:00
parent 196e10bce4
commit af36dc7d76
4 changed files with 83 additions and 25 deletions

View File

@ -22,23 +22,6 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
target_compile_options("${wasmTarget}" INTERFACE -O2 -msimd128 -msse -msse2) target_compile_options("${wasmTarget}" INTERFACE -O2 -msimd128 -msse -msse2)
endif() endif()
# Hardcode wasm memory size. Emscripten does not currently support memory growth
# (ALLOW_MEMORY_GROWTH) in pthreads mode, and requires specifying the memory size
# at build time. Further, browsers limit the maximum initial memory size to 1GB.
# QT_WASM_INITIAL_MEMORY must be a multiple of 64KB (i.e. 65536)
if(NOT DEFINED QT_WASM_INITIAL_MEMORY)
if(QT_FEATURE_thread)
set(QT_WASM_INITIAL_MEMORY "1GB")
else()
set(QT_WASM_INITIAL_MEMORY "20MB") # emscripten default is 16MB, we need slightly more sometimes
endif()
endif()
if(DEFINED QT_WASM_INITIAL_MEMORY)
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
message("Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY}")
endif()
if (QT_FEATURE_opengles3) if (QT_FEATURE_opengles3)
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FULL_ES3=1") target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FULL_ES3=1")
@ -58,14 +41,6 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
if (QT_FEATURE_thread) if (QT_FEATURE_thread)
target_compile_options("${wasmTarget}" INTERFACE "SHELL:-pthread") target_compile_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
target_link_options("${wasmTarget}" INTERFACE "SHELL:-pthread") target_link_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
set(POOL_SIZE 4)
if(DEFINED QT_WASM_PTHREAD_POOL_SIZE)
set(POOL_SIZE ${QT_WASM_PTHREAD_POOL_SIZE})
endif()
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s PTHREAD_POOL_SIZE=${POOL_SIZE}")
message("Setting PTHREAD_POOL_SIZE to ${POOL_SIZE}")
else() else()
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH=1") target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH=1")
endif() endif()

View File

@ -83,3 +83,5 @@ macro.cmakepropertyandroidonly = "\\note This property is used only if targeting
macro.cmakevariableandroidonly = "\\note This variable is used only if targeting the Android platform." macro.cmakevariableandroidonly = "\\note This variable is used only if targeting the Android platform."
macro.versionlessCMakeCommandsNote = "If \\l{Versionless commands}{versionless commands} are disabled, use \\c{\1} instead. It supports the same set of arguments as this command." macro.versionlessCMakeCommandsNote = "If \\l{Versionless commands}{versionless commands} are disabled, use \\c{\1} instead. It supports the same set of arguments as this command."
macro.cmakepropertywebassemblyonly = "\\note This property is used only if targeting the WebAssembly platform."

View File

@ -18,5 +18,40 @@ function(_qt_internal_wasm_add_target_helpers target)
configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg" configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg"
qtlogo.svg COPYONLY) qtlogo.svg COPYONLY)
if(QT_FEATURE_thread)
set(POOL_SIZE 4)
get_target_property(_tmp_poolSize "${target}" QT_WASM_PTHREAD_POOL_SIZE)
if(_tmp_poolSize)
set(POOL_SIZE ${_tmp_poolSize})
elseif(DEFINED QT_WASM_PTHREAD_POOL_SIZE)
set(POOL_SIZE ${QT_WASM_PTHREAD_POOL_SIZE})
endif()
target_link_options("${target}" PRIVATE "SHELL:-s PTHREAD_POOL_SIZE=${POOL_SIZE}")
message(DEBUG "Setting PTHREAD_POOL_SIZE to ${POOL_SIZE} for ${target}")
endif()
# Hardcode wasm memory size. Emscripten does not currently support memory growth
# (ALLOW_MEMORY_GROWTH) in pthreads mode, and requires specifying the memory size
# at build time. Further, browsers limit the maximum initial memory size to 1GB.
# QT_WASM_INITIAL_MEMORY must be a multiple of 64KB (i.e. 65536)
get_target_property(_tmp_initialMemory "${target}" QT_WASM_INITIAL_MEMORY)
if(_tmp_initialMemory)
set(QT_WASM_INITIAL_MEMORY "${_tmp_initialMemory}")
elseif(NOT DEFINED QT_WASM_INITIAL_MEMORY)
if(QT_FEATURE_thread)
set(QT_WASM_INITIAL_MEMORY "1GB")
else()
# emscripten default is 16MB, we need slightly more sometimes
set(QT_WASM_INITIAL_MEMORY "20MB")
endif()
endif()
if(DEFINED QT_WASM_INITIAL_MEMORY)
target_link_options("${target}"
PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
message(DEBUG "-- Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY} for ${target}")
endif()
endif() endif()
endfunction() endfunction()

View File

@ -384,3 +384,49 @@ the property value overrides the runtime path where the resource file is found.
\sa{The Qt Resource System} \sa{The Qt Resource System}
*/ */
/*!
\page cmake-target-property-QT_WASM_PTHREAD_POOL_SIZE.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
\title QT_WASM_PTHREAD_POOL_SIZE
\target cmake-target-property-QT_WASM_PTHREAD_POOL_SIZE
\summary {Internal WebAssembly thread pool size.}
\cmakepropertysince 6.2.4
\preliminarycmakeproperty
\cmakepropertywebassemblyonly
Specifies the number of web workers (threads) to create at application startup.
Qt allocates a pool size of 4 by default. This means the app can use
4 additional threads besides the main thread, without the additional overhead
of creating a new web worker, which may deadlock if the main thread created it
and join()s the thread without returning control to the event loop first.
Translates into the Emscripten compiler setting of PTHREAD_POOL_SIZE.
For more information, see \l{https://emscripten.org/docs/porting/pthreads.html}{Pthreads support}.
*/
/*!
\page cmake-target-property-QT_WASM_INITIAL_MEMORY.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
\title QT_WASM_INITIAL_MEMORY
\target cmake-target-property-QT_WASM_INITIAL_MEMORY
\summary {Internal WebAssembly initial memory.}
\cmakepropertysince 6.2.4
\preliminarycmakeproperty
\cmakepropertywebassemblyonly
Specifies the initial amount of memory to use, in bytes. Using more will cause the
browser to copy the old heap into a new one. Translates into the
Emscripten compiler setting of INITIAL_MEMORY.
QT_WASM_INITIAL_MEMORY must be a multiple of 65536 bytes.
For more information, see \l{https://github.com/emscripten-core/emscripten/blob/main/src/settings.js}{Emscripten compiler settings}.
*/