From 836ecad10545a7b521367a383f605d7421cd97ec Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 3 May 2026 13:04:31 +0200 Subject: [PATCH] update wgpu-native to 29.0.0.0 (#4222) --- .github/workflows/android-ci.yml | 8 ++-- .github/workflows/ios-ci.yml | 9 +++- include/mbgl/webgpu/wgpu_cpp_compat.hpp | 7 +++ platform/glfw/glfw_webgpu_backend_impl.ipp | 2 +- src/mbgl/webgpu/headless_backend.cpp | 4 +- src/mbgl/webgpu/webgpu_cpp_impl.cpp | 6 +++ vendor/wgpu-native | 2 +- vendor/wgpu.cmake | 54 +++++++++++++++------- 8 files changed, 67 insertions(+), 25 deletions(-) diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 5cb384da9..0948dfdc2 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -380,9 +380,6 @@ jobs: with: toolchain: stable - - name: Add Android Rust target - run: rustup target add ${{ env.RUST_TARGET }} - - name: Configure cargo for Android NDK linker run: | LATEST_NDK=$(find "$ANDROID_SDK_ROOT/ndk" -mindepth 1 -maxdepth 1 -type d | sort -V | tail -n 1) @@ -396,6 +393,11 @@ jobs: - name: Pre-build wgpu-native for Android working-directory: vendor/wgpu-native run: | + # vendor/wgpu-native pins its own rust toolchain; install targets for that active toolchain + ACTIVE_TOOLCHAIN=$(rustup show active-toolchain | awk '{print $1}') + rustup target add ${{ env.RUST_TARGET }} --toolchain "$ACTIVE_TOOLCHAIN" + rustup target list --toolchain "$ACTIVE_TOOLCHAIN" --installed | grep -x '${{ env.RUST_TARGET }}' + LATEST_NDK=$(find "$ANDROID_SDK_ROOT/ndk" -mindepth 1 -maxdepth 1 -type d | sort -V | tail -n 1) NDK_PREBUILT="$LATEST_NDK/toolchains/llvm/prebuilt/linux-x86_64" RESOURCE_DIR=$("$NDK_PREBUILT/bin/clang" --print-resource-dir) diff --git a/.github/workflows/ios-ci.yml b/.github/workflows/ios-ci.yml index a73d8cbd1..bcc611cdc 100644 --- a/.github/workflows/ios-ci.yml +++ b/.github/workflows/ios-ci.yml @@ -260,8 +260,13 @@ jobs: with: toolchain: stable - - name: Add iOS Rust target - run: rustup target add aarch64-apple-ios + - name: Ensure iOS Rust targets are installed for active toolchain + working-directory: vendor/wgpu-native + run: | + # vendor/wgpu-native pins its own rust toolchain; install targets for that active toolchain + ACTIVE_TOOLCHAIN=$(rustup show active-toolchain | awk '{print $1}') + rustup target add aarch64-apple-ios --toolchain "$ACTIVE_TOOLCHAIN" + rustup target list --toolchain "$ACTIVE_TOOLCHAIN" --installed | grep -x 'aarch64-apple-ios' - name: Configure build with CMake run: cmake --preset ios-webgpu-wgpu diff --git a/include/mbgl/webgpu/wgpu_cpp_compat.hpp b/include/mbgl/webgpu/wgpu_cpp_compat.hpp index 29bae7bb9..59ef0fb2f 100644 --- a/include/mbgl/webgpu/wgpu_cpp_compat.hpp +++ b/include/mbgl/webgpu/wgpu_cpp_compat.hpp @@ -15,7 +15,14 @@ #include #elif MLN_WEBGPU_IMPL_WGPU // For wgpu-native backend, use the WebGPU-Cpp wrapper +// TODO: remove this workaround as soon as https://github.com/eliemichel/WebGPU-Cpp/issues/35 is fixed +#ifndef _NULLABLE +#define _NULLABLE WGPU_NULLABLE +#endif #include + +#undef _NULLABLE + #endif #if defined(__clang__) diff --git a/platform/glfw/glfw_webgpu_backend_impl.ipp b/platform/glfw/glfw_webgpu_backend_impl.ipp index 1dab871cd..36cc15961 100644 --- a/platform/glfw/glfw_webgpu_backend_impl.ipp +++ b/platform/glfw/glfw_webgpu_backend_impl.ipp @@ -606,7 +606,7 @@ GLFWWebGPUBackend::GLFWWebGPUBackend(GLFWwindow* window_, bool capFrameRate) x11Desc.window = x11Window; wgpu::SurfaceDescriptor surfaceDesc = {}; - surfaceDesc.nextInChain = reinterpret_cast(&x11Desc); + surfaceDesc.nextInChain = reinterpret_cast(&x11Desc); wgpuSurface = wgpuInstance.createSurface(surfaceDesc); #endif diff --git a/src/mbgl/webgpu/headless_backend.cpp b/src/mbgl/webgpu/headless_backend.cpp index e4330f7a0..e81891f93 100644 --- a/src/mbgl/webgpu/headless_backend.cpp +++ b/src/mbgl/webgpu/headless_backend.cpp @@ -16,9 +16,9 @@ namespace webgpu { class HeadlessRenderableResource final : public webgpu::RenderableResource { public: - HeadlessRenderableResource(HeadlessBackend&, webgpu::Context& context_, Size size) + HeadlessRenderableResource(HeadlessBackend&, webgpu::Context& context_, Size size_) : context(context_), - size(size) { + size(size_) { // Create offscreen texture using the proper WebGPU OffscreenTexture class offscreenTexture = context.createOffscreenTexture(size, gfx::TextureChannelDataType::UnsignedByte, true, true); } diff --git a/src/mbgl/webgpu/webgpu_cpp_impl.cpp b/src/mbgl/webgpu/webgpu_cpp_impl.cpp index a4f599cea..23b806ed3 100644 --- a/src/mbgl/webgpu/webgpu_cpp_impl.cpp +++ b/src/mbgl/webgpu/webgpu_cpp_impl.cpp @@ -3,4 +3,10 @@ // for the WebGPU C++ wrapper functions #define WEBGPU_CPP_IMPLEMENTATION +// TODO: remove this workaround as soon as https://github.com/eliemichel/WebGPU-Cpp/issues/35 is fixed +#ifndef _NULLABLE +#define _NULLABLE WGPU_NULLABLE +#endif #include + +#undef _NULLABLE diff --git a/vendor/wgpu-native b/vendor/wgpu-native index 768f15f6a..d2e3330ad 160000 --- a/vendor/wgpu-native +++ b/vendor/wgpu-native @@ -1 +1 @@ -Subproject commit 768f15f6ace8e4ec8e8720d5732b29e0b34250a8 +Subproject commit d2e3330ade4ae1bb238d76b485926f067e7ee64c diff --git a/vendor/wgpu.cmake b/vendor/wgpu.cmake index 8042c7b76..221c7af6a 100644 --- a/vendor/wgpu.cmake +++ b/vendor/wgpu.cmake @@ -88,7 +88,23 @@ endmacro() mln_wgpu_find_library() -if(NOT WGPU_LIBRARY) +if(NOT WGPU_LIBRARY OR MLN_WGPU_NATIVE_VERSION) + # Use a specific version of WGPU. This is required when to a rust application + # which uses wgpu directly instead of wgpu-native + if (MLN_WGPU_NATIVE_VERSION) + execute_process( + COMMAND git checkout ${MLN_WGPU_NATIVE_VERSION} + WORKING_DIRECTORY ${_mln_wgpu_source_dir} + RESULT_VARIABLE _git_checkout_wgpu_result + OUTPUT_VARIABLE _git_checkout_wgpu_output + ERROR_VARIABLE _git_checkout_wgpu_error + ) + + if(NOT _git_checkout_wgpu_result EQUAL 0) + message(FATAL_ERROR "Failed to checkout wgpu-native version '${MLN_WGPU_NATIVE_VERSION}': ${_git_checkout_wgpu_error}\n") + endif() + endif() + message(STATUS "Pre-built wgpu-native library not found, attempting to build from source...") # Check if cargo is available @@ -147,9 +163,16 @@ else() message(STATUS "Found wgpu-native library: ${WGPU_LIBRARY}") endif() +# Create compatibility shims for Dawn header paths if they don't exist +set(_webgpu-cpp-output_dir "${CMAKE_CURRENT_BINARY_DIR}/webgpu-cpp") +set(_compat_shim_dir "${_webgpu-cpp-output_dir}/webgpu") +set(_compat_shim_header "${_compat_shim_dir}/webgpu_cpp.h") +set(_compat_shim_webgpu_h "${_compat_shim_dir}/webgpu.h") +set(_compat_shim_wgpu_h "${_compat_shim_dir}/wgpu.h") +file(MAKE_DIRECTORY "${_compat_shim_dir}") + # Generate WebGPU-Cpp wrapper if needed -set(_webgpu_cpp_dir "${PROJECT_SOURCE_DIR}/vendor/webgpu-cpp") -set(_webgpu_cpp_header "${_webgpu_cpp_dir}/webgpu.hpp") +set(_webgpu_cpp_header "${_webgpu-cpp-output_dir}/webgpu.hpp") if(NOT EXISTS "${_webgpu_cpp_header}") message(STATUS "Generating WebGPU-Cpp wrapper...") @@ -167,7 +190,8 @@ if(NOT EXISTS "${_webgpu_cpp_header}") COMMAND ${PYTHON_EXECUTABLE} generate.py --use-init-macros --header ${_mln_wgpu_source_dir}/ffi/webgpu-headers/webgpu.h - WORKING_DIRECTORY ${_webgpu_cpp_dir} + --output ${_webgpu_cpp_header} + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/vendor/webgpu-cpp" RESULT_VARIABLE _gen_result OUTPUT_VARIABLE _gen_output ERROR_VARIABLE _gen_error @@ -181,15 +205,9 @@ if(NOT EXISTS "${_webgpu_cpp_header}") message(STATUS "Successfully generated WebGPU-Cpp wrapper") endif() -# Create compatibility shims for Dawn header paths if they don't exist -set(_compat_shim_dir "${_webgpu_cpp_dir}/wgpu-native/webgpu") -set(_compat_shim_header "${_compat_shim_dir}/webgpu_cpp.h") -set(_compat_shim_webgpu_h "${_compat_shim_dir}/webgpu.h") - if(NOT EXISTS "${_compat_shim_header}") message(STATUS "Creating WebGPU-Cpp compatibility shim...") - file(MAKE_DIRECTORY "${_compat_shim_dir}") file(WRITE "${_compat_shim_header}" "#pragma once // Compatibility shim for Dawn header paths @@ -197,7 +215,13 @@ if(NOT EXISTS "${_compat_shim_header}") // for both Dawn and wgpu-native backends // Include the WebGPU-Cpp wrapper -#include \"../../webgpu.hpp\" +// TODO: remove this workaround as soon as https://github.com/eliemichel/WebGPU-Cpp/issues/35 is fixed +#ifndef _NULLABLE + #define _NULLABLE WGPU_NULLABLE +#endif +#include \"${_webgpu_cpp_header}\" + +#undef _NULLABLE ") message(STATUS "Successfully created WebGPU-Cpp compatibility shim") @@ -220,7 +244,6 @@ if(NOT EXISTS "${_compat_shim_webgpu_h}") endif() # Also create wgpu.h shim for wgpu-native specific includes -set(_compat_shim_wgpu_h "${_compat_shim_dir}/wgpu.h") if(NOT EXISTS "${_compat_shim_wgpu_h}") message(STATUS "Creating wgpu.h compatibility shim...") @@ -245,10 +268,9 @@ target_link_libraries(mbgl-vendor-wgpu INTERFACE ${WGPU_LIBRARY}) # Add include directories for webgpu.h, wgpu.h, and C++ wrapper target_include_directories(mbgl-vendor-wgpu SYSTEM INTERFACE - ${_webgpu_cpp_dir} # For generated webgpu.hpp - ${_webgpu_cpp_dir}/wgpu-native # For webgpu/webgpu_cpp.h compatibility shim - ${_mln_wgpu_source_dir}/ffi/webgpu-headers - ${_mln_wgpu_source_dir}/ffi + ${_webgpu-cpp-output_dir} # For webgpu.hpp webgpu/webgpu_cpp.h compatibility shim + ${_mln_wgpu_source_dir}/ffi/webgpu-headers # webgpu.h + ${_mln_wgpu_source_dir}/ffi # wgpu.h ) # Platform-specific system libraries that wgpu-native needs