Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmake/webgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ list(APPEND
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/buffer_resource.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/context.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/command_encoder.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/headless_backend.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/renderer_backend.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/drawable.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/drawable_builder.cpp
Expand Down Expand Up @@ -124,3 +123,8 @@ elseif(MLN_WEBGPU_IMPL_WGPU)
list(APPEND SRC_FILES ${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/webgpu_cpp_impl.cpp)
endif()
endif()

# Headless backend uses Dawn native / wgpu-native bootstrap; skip for emdawnwebgpu.
if(NOT MLN_WEBGPU_EMDAWN)
list(APPEND SRC_FILES ${PROJECT_SOURCE_DIR}/src/mbgl/webgpu/headless_backend.cpp)
endif()
2 changes: 1 addition & 1 deletion src/mbgl/webgpu/offscreen_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class OffscreenTextureResource final : public webgpu::RenderableResource {
}

// Process all pending device operations to ensure rendering is complete
#if MLN_WEBGPU_IMPL_DAWN
#if MLN_WEBGPU_IMPL_DAWN && !MLN_WEBGPU_EMDAWN
wgpuDeviceTick(device);
#endif

Expand Down
14 changes: 14 additions & 0 deletions vendor/dawn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ if(NOT MLN_WITH_WEBGPU)
return()
endif()

if(MLN_WEBGPU_EMDAWN)
message(STATUS "Configuring emdawnwebgpu (host supplies --use-port=emdawnwebgpu)")
add_library(mbgl-vendor-dawn INTERFACE)
Comment on lines +12 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a stack-switching mode for emdawn readback

For emdawn builds this target only asks the host to provide the port, but it never requires Asyncify/JSPI. The same build still takes the Dawn readback path in OffscreenTextureResource::readStillImage() and calls wgpuBufferMapAsync with WGPUCallbackMode_WaitAnyOnly followed by wgpuInstanceWaitAny, so browser snapshot/readback paths need a stack-switching mode to synchronously wait on the JavaScript promise; without adding -sASYNCIFY=1/-sJSPI=1 or disabling this sync path for emdawn, those calls can trap or hang at runtime instead of returning pixels.

Useful? React with 👍 / 👎.

Comment on lines +12 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate the emdawn port flags from the target

This branch creates mbgl-vendor-dawn as a metadata-only target and relies on the caller to supply --use-port=emdawnwebgpu, but the emdawn port must be present during compilation as well as final linking because core sources include <webgpu/webgpu.h> and <webgpu/webgpu_cpp.h>. If someone enables MLN_WEBGPU_EMDAWN without also injecting that flag globally into every compile and link invocation, the new CMake option still fails to find the headers or link the JS glue; attach the required compile/link options (or a real emdawn target) to this interface target instead of only logging the requirement.

Useful? React with 👍 / 👎.

set_target_properties(
mbgl-vendor-dawn
PROPERTIES
INTERFACE_MAPLIBRE_NAME "emdawnwebgpu"
INTERFACE_MAPLIBRE_URL "https://dawn.googlesource.com/dawn"
INTERFACE_MAPLIBRE_AUTHOR "Chromium Dawn Team"
INTERFACE_MAPLIBRE_LICENSE "${PROJECT_SOURCE_DIR}/vendor/dawn/LICENSE"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Point emdawn at an existing license file

When MLN_WEBGPU_EMDAWN is enabled, this branch returns before Dawn is fetched into vendor/dawn, but scripts/license.cmake later walks mbgl-core's linked targets and fatals if INTERFACE_MAPLIBRE_LICENSE does not exist. In a clean checkout where vendor/dawn is absent, any non-MLN_WITH_CORE_ONLY configure using the new emdawn target registers this missing path and cannot complete; use a checked-in/license path that exists for the emdawn port or skip registering a nonexistent file.

Useful? React with 👍 / 👎.

@birkskyum birkskyum Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sargunv can you address this?

)
return()
endif()

if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
Expand Down
14 changes: 14 additions & 0 deletions vendor/webgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@

set(MLN_WEBGPU_IMPL_DAWN OFF CACHE STRING "WebGPU with Dawn implementation")
set(MLN_WEBGPU_IMPL_WGPU OFF CACHE STRING "WebGPU with wgpu implementation")
set(MLN_WEBGPU_EMDAWN OFF
CACHE BOOL "Use Emscripten emdawnwebgpu with Dawn headers (requires MLN_WEBGPU_IMPL_DAWN)")

if(MLN_WITH_WEBGPU)
if(MLN_WEBGPU_EMDAWN AND NOT EMSCRIPTEN)
message(FATAL_ERROR "MLN_WEBGPU_EMDAWN requires Emscripten")
endif()

if(MLN_WEBGPU_EMDAWN AND NOT MLN_WEBGPU_IMPL_DAWN)
message(FATAL_ERROR "MLN_WEBGPU_EMDAWN requires MLN_WEBGPU_IMPL_DAWN")
endif()

if(MLN_WEBGPU_IMPL_DAWN)
message(STATUS "Using Dawn as WebGPU backend")
add_compile_definitions(MLN_WEBGPU_IMPL_DAWN)
if(MLN_WEBGPU_EMDAWN)
message(STATUS "Using emdawnwebgpu port for browser WebGPU")
add_compile_definitions(MLN_WEBGPU_EMDAWN)
endif()

elseif(MLN_WEBGPU_IMPL_WGPU)
message(STATUS "Using wgpu as WebGPU backend")
Expand Down
Loading