From ff907736ef4583cb617b82a140e0edf00252deea Mon Sep 17 00:00:00 2001 From: richerfu <32590310+richerfu@users.noreply.github.com> Date: Thu, 13 Feb 2025 11:01:50 +0800 Subject: [PATCH] feat(gles): support gles backend on openharmony (#7085) * fix(gles): fix gles backend crash on openharmony * docs: add changelog * ci: add OpenHarmony to CI * Update .github/workflows/ci.yml --------- Co-authored-by: Connor Fitzgerald --- .github/workflows/ci.yml | 7 +++++++ CHANGELOG.md | 4 ++++ wgpu-hal/src/gles/egl.rs | 20 +++++++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a932ffcd3..40ab17a45a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,6 +145,13 @@ jobs: tier: 2 kind: native + # OpenHarmony + - name: OpenHarmony aarch64 + os: ubuntu-22.04 + target: aarch64-unknown-linux-ohos + tier: 2 + kind: native + # WebGPU/WebGL - name: WebAssembly os: ubuntu-22.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index b3c5ebdda7..234a8d65bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,10 @@ By @brodycj in [#6924](https://github.com/gfx-rs/wgpu/pull/6924). - Stop naga causing undefined behavior when a ray query misses. By @Vecvec in [#6752](https://github.com/gfx-rs/wgpu/pull/6752). +#### Gles + +- Support OpenHarmony render with `gles`. By @richerfu in [#7085](https://github.com/gfx-rs/wgpu/pull/7085) + #### Dx12 - Fix HLSL storage format generation. By @Vecvec in [#6993](https://github.com/gfx-rs/wgpu/pull/6993) and [#7104](https://github.com/gfx-rs/wgpu/pull/7104) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index b7d9868609..46ff37fbc1 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -259,11 +259,12 @@ fn choose_config( log::warn!("EGL says it can present to the window but not natively",); } // Android emulator can't natively present either. - let tier_threshold = if cfg!(target_os = "android") || cfg!(windows) { - 1 - } else { - 2 - }; + let tier_threshold = + if cfg!(target_os = "android") || cfg!(windows) || cfg!(target_env = "ohos") { + 1 + } else { + 2 + }; return Ok((config, tier_max >= tier_threshold)); } Ok(None) => { @@ -956,6 +957,7 @@ impl crate::Instance for Instance { (Rwh::Xcb(_), _) => {} (Rwh::Win32(_), _) => {} (Rwh::AppKit(_), _) => {} + (Rwh::OhosNdk(_), _) => {} #[cfg(target_os = "android")] (Rwh::AndroidNdk(handle), _) => { let format = inner @@ -1306,6 +1308,7 @@ impl crate::Surface for Surface { (WindowKind::Unknown, Rwh::AndroidNdk(handle)) => { handle.a_native_window.as_ptr() } + (WindowKind::Unknown, Rwh::OhosNdk(handle)) => handle.native_window.as_ptr(), (WindowKind::Wayland, Rwh::Wayland(handle)) => { let library = &self.wsi.display_owner.as_ref().unwrap().library; let wl_egl_window_create: libloading::Symbol = @@ -1349,8 +1352,11 @@ impl crate::Surface for Surface { // We don't want any of the buffering done by the driver, because we // manage a swapchain on our side. // Some drivers just fail on surface creation seeing `EGL_SINGLE_BUFFER`. - if cfg!(any(target_os = "android", target_os = "macos")) - || cfg!(windows) + if cfg!(any( + target_os = "android", + target_os = "macos", + target_env = "ohos" + )) || cfg!(windows) || self.wsi.kind == WindowKind::AngleX11 { khronos_egl::BACK_BUFFER