core: emdawnwebgpu build support#4370
Conversation
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.
There was a problem hiding this comment.
💡 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".
| 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" |
There was a problem hiding this comment.
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 👍 / 👎.
| message(STATUS "Configuring emdawnwebgpu (host supplies --use-port=emdawnwebgpu)") | ||
| add_library(mbgl-vendor-dawn INTERFACE) |
There was a problem hiding this comment.
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 👍 / 👎.
| message(STATUS "Configuring emdawnwebgpu (host supplies --use-port=emdawnwebgpu)") | ||
| add_library(mbgl-vendor-dawn INTERFACE) |
There was a problem hiding this comment.
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 👍 / 👎.
Bloaty Results 🐋Compared to main Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4370-compared-to-main.txtCompared to d387090 (legacy) Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-4370-compared-to-legacy.txt |
|
Benchmark Results ⚡ Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-4370-compared-to-main.txt |
Bloaty Results (iOS) 🐋Compared to main Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-4370-compared-to-main.txt |
https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md
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.