Skip to content

Commit

Permalink
WebGPU: Fixed build settings for pthreads (close #583)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets authored and TheMostDiligent committed Jul 30, 2024
1 parent c3c0542 commit 1f1d2cb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 3 deletions.
13 changes: 13 additions & 0 deletions BuildTools/CMake/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,16 @@ macro(FetchContent_DeclareShallowGit Name GIT_REPOSITORY GitRepository GIT_TAG G
git reset --hard FETCH_HEAD
)
endmacro()

function(set_targets_emscripten_properties)
if (PLATFORM_EMSCRIPTEN)
foreach(_TARGET IN LISTS ARGN)
get_target_property(_TARGET_TYPE ${_TARGET} TYPE)
if (_TARGET_TYPE STREQUAL "STATIC_LIBRARY")
target_compile_options(${_TARGET} PRIVATE
"-pthread"
"-mbulk-memory")
endif()
endforeach()
endif()
endfunction()
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ endif()


add_library(Diligent-BuildSettings INTERFACE)

if (PLATFORM_EMSCRIPTEN)
target_compile_options(Diligent-BuildSettings INTERFACE
"-pthread"
"-mbulk-memory"
)
endif()

target_link_libraries(Diligent-BuildSettings INTERFACE Diligent-PublicBuildSettings)

foreach(DBG_CONFIG ${DEBUG_CONFIGURATIONS})
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineOpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ elseif(PLATFORM_IOS)
# Silence GLES deprecation warnings
target_compile_definitions(Diligent-GraphicsEngineOpenGL-static PUBLIC GLES_SILENCE_DEPRECATION)
elseif(PLATFORM_EMSCRIPTEN)
target_link_options(Diligent-GraphicsEngineOpenGL-static PUBLIC "SHELL: -s FULL_ES3=1 -s DISABLE_EXCEPTION_CATCHING=0")
target_link_options(Diligent-GraphicsEngineOpenGL-static PUBLIC "SHELL: -s FULL_ES3=1 -s USE_PTHREADS=1")
endif()

if(PLATFORM_WIN32)
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineWebGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ PRIVATE
)

if (PLATFORM_EMSCRIPTEN)
target_link_options(Diligent-GraphicsEngineWebGPU-static PUBLIC "SHELL: -s USE_WEBGPU=1")
target_link_options(Diligent-GraphicsEngineWebGPU-static PUBLIC "SHELL: -s USE_WEBGPU=1 -s USE_PTHREADS=1")
endif()

target_compile_definitions(Diligent-GraphicsEngineWebGPU-shared PUBLIC ENGINE_DLL=1)
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineWebGPU/src/SwapChainWebGPUImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class WebGPUSwapChainPresentCommand
wgpuQueueSubmit(pDeviceContext->GetWebGPUQueue(), 1, &wgpuCmdBuffer.Get());

#if PLATFORM_EMSCRIPTEN
emscripten_request_animation_frame([](double Time, void* pUserData) -> EM_BOOL { return false; }, nullptr);
emscripten_request_animation_frame([](double Time, void* pUserData) -> EM_BOOL { return EM_FALSE; }, nullptr);
#else
wgpuSurfacePresent(pSwapChain->GetWebGPUSurface());
#endif
Expand Down
9 changes: 9 additions & 0 deletions ThirdParty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ if (VULKAN_SUPPORTED OR METAL_SUPPORTED OR WEBGPU_SUPPORTED OR (ARCHIVER_SUPPORT
add_subdirectory(glslang)
set_directory_root_folder("glslang" "DiligentCore/ThirdParty/glslang")

if (PLATFORM_EMSCRIPTEN)
set_targets_emscripten_properties(MachineIndependent)
endif()

# glslang "kindly" sets global CMAKE_DEBUG_POSTFIX to "d", which we have to unset now
unset(CMAKE_DEBUG_POSTFIX CACHE)

Expand Down Expand Up @@ -181,6 +185,11 @@ if ((${DILIGENT_BUILD_GOOGLE_TEST}) AND (NOT TARGET gtest))

get_target_property(GTEST_SOURCE_DIR gtest SOURCE_DIR)
install(FILES "googletest/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME googletest-License.txt)

if (PLATFORM_EMSCRIPTEN)
find_targets_in_directory(GTEST_TARGETS ${GTEST_SOURCE_DIR})
set_targets_emscripten_properties(${GTEST_TARGETS})
endif()
endif()

if (NOT TARGET xxHash::xxhash)
Expand Down
5 changes: 5 additions & 0 deletions ThirdParty/dawn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ set(DAWN_ABSEIL_DIR "${abseil-cpp_SOURCE_DIR}" CACHE STRING "Directo

FetchContent_MakeAvailable(dawn)

if (PLATFORM_EMSCRIPTEN)
find_targets_in_directory(DAWN_TARGETS ${dawn_SOURCE_DIR})
set_targets_emscripten_properties(${DAWN_TARGETS})
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(tint_api PRIVATE -Wno-switch-default)
endif()
Expand Down

0 comments on commit 1f1d2cb

Please sign in to comment.