Skip to content

core: emdawnwebgpu build support#4370

Open
sargunv wants to merge 4 commits into
maplibre:mainfrom
sargunv:codex/emdawn-webgpu-build-support
Open

core: emdawnwebgpu build support#4370
sargunv wants to merge 4 commits into
maplibre:mainfrom
sargunv:codex/emdawn-webgpu-build-support

Conversation

@sargunv

@sargunv sargunv commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md

Emdawnwebgpu is Dawn‘s implementation of webgpu.h for Emscripten (on top of the WebGPU JS API). It is a fork of Emscripten’s original USE_WEBGPU bindings, and while it is maintained in Dawn, it works in any browser supporting WebGPU (modulo individual feature support).

Emdawnwebgpu provides everything necessary to use <webgpu/webgpu.h> and the Dawn-style <webgpu/webgpu_cpp.h> with Emscripten.

Excluded: the existing headless backend and requires dawn native. emdawn also doesn't expose wgpuDeviceTick.

AI disclosure: used multiple models, primarily gpt-5.5, to explore and prototype a browser webgpu build, then extract these targeted upstream fixes.

sargunv added 4 commits June 28, 2026 14:59
Add an MLN_WEBGPU_EMDAWN build option that uses Dawn headers and compile definitions while treating the Emscripten emdawnwebgpu port as the WebGPU implementation provider.
Do not compile the native WebGPU headless backend for emdawn builds because the browser host supplies the device and surface model.
Avoid calling the native Dawn device tick hook on emdawn builds, where browser WebGPU progresses through the browser event loop.
@github-actions github-actions Bot added build Related to build, configuration or CI/CD core Changes that affect the C++ core of MapLibre Native WebGPU labels Jun 28, 2026
@sargunv sargunv marked this pull request as ready for review June 28, 2026 23:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd551ea140

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vendor/dawn.cmake
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?

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

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 thread vendor/dawn.cmake
Comment on lines +12 to +13
message(STATUS "Configuring emdawnwebgpu (host supplies --use-port=emdawnwebgpu)")
add_library(mbgl-vendor-dawn INTERFACE)

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 👍 / 👎.

@louwers louwers requested a review from birkskyum June 30, 2026 19:44
@louwers louwers enabled auto-merge (squash) June 30, 2026 19:45
@github-actions

Copy link
Copy Markdown
Contributor

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4370-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +51% +59.1Mi  +467% +27.9Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4370-compared-to-legacy.txt

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Results ⚡

Benchmark                                                     Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------
OVERALL_GEOMEAN                                            -0.0149         -0.0151             0             0             0             0

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-4370-compared-to-main.txt

@github-actions

Copy link
Copy Markdown
Contributor

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-4370-compared-to-main.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Related to build, configuration or CI/CD core Changes that affect the C++ core of MapLibre Native WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants