From 25b4cda52484a0d58711f8dcd1a634ceb8beca90 Mon Sep 17 00:00:00 2001 From: csmoe Date: Thu, 9 Jul 2026 01:56:53 +0800 Subject: [PATCH] Add angle as gl backend on Windows (#9422) --- CHANGELOG.md | 4 + Cargo.lock | 12 +- Cargo.toml | 3 +- README.md | 2 +- docs/broadcast_license.nu | 3 +- wgpu-core/Cargo.toml | 26 ++- wgpu-core/platform-deps/apple/src/lib.rs | 4 +- wgpu-core/platform-deps/emscripten/src/lib.rs | 4 +- .../linux-android-bsd/Cargo.toml | 29 +++ .../LICENSE.APACHE | 0 .../LICENSE.MIT | 0 .../platform-deps/linux-android-bsd/README.md | 3 + .../linux-android-bsd/src/lib.rs | 1 + wgpu-core/platform-deps/wasm/src/lib.rs | 4 +- .../windows-linux-android/README.md | 3 - .../windows-linux-android/src/lib.rs | 3 - .../Cargo.toml | 4 +- .../platform-deps/windows/LICENSE.APACHE | 176 ++++++++++++++++++ wgpu-core/platform-deps/windows/LICENSE.MIT | 21 +++ wgpu-core/platform-deps/windows/README.md | 2 + wgpu-core/platform-deps/windows/src/lib.rs | 1 + wgpu-hal/Cargo.toml | 3 +- wgpu-hal/src/gles/egl.rs | 50 +++-- wgpu-hal/src/gles/mod.rs | 48 +++-- wgpu-types/src/backend.rs | 4 +- wgpu/build.rs | 2 +- 26 files changed, 336 insertions(+), 76 deletions(-) create mode 100644 wgpu-core/platform-deps/linux-android-bsd/Cargo.toml rename wgpu-core/platform-deps/{windows-linux-android => linux-android-bsd}/LICENSE.APACHE (100%) rename wgpu-core/platform-deps/{windows-linux-android => linux-android-bsd}/LICENSE.MIT (100%) create mode 100644 wgpu-core/platform-deps/linux-android-bsd/README.md create mode 100644 wgpu-core/platform-deps/linux-android-bsd/src/lib.rs delete mode 100644 wgpu-core/platform-deps/windows-linux-android/README.md delete mode 100644 wgpu-core/platform-deps/windows-linux-android/src/lib.rs rename wgpu-core/platform-deps/{windows-linux-android => windows}/Cargo.toml (84%) create mode 100644 wgpu-core/platform-deps/windows/LICENSE.APACHE create mode 100644 wgpu-core/platform-deps/windows/LICENSE.MIT create mode 100644 wgpu-core/platform-deps/windows/README.md create mode 100644 wgpu-core/platform-deps/windows/src/lib.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index c0fac98a6..dea3a655a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,10 @@ Bottom level categories: - Add `BufferBinding::buffer`, a public read accessor for the bound buffer, which was previously inaccessible to out-of-tree `wgpu_hal::Api` implementations. By @danlehmann in [#9820](https://github.com/gfx-rs/wgpu/pull/9820). +#### GLES + +- Add ANGLE as an opt-in OpenGL backend on Windows via `cfg(windows_angle)`, while keeping the `angle` feature for ANGLE on macOS/iOS. By @csmoe in [#9422](https://github.com/gfx-rs/wgpu/pull/9422). + ### Changes #### naga diff --git a/Cargo.lock b/Cargo.lock index 2f03ed105..af7ddd4a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4720,8 +4720,9 @@ dependencies = [ "thiserror 2.0.18", "wgpu-core-deps-apple", "wgpu-core-deps-emscripten", + "wgpu-core-deps-linux-android-bsd", "wgpu-core-deps-wasm", - "wgpu-core-deps-windows-linux-android", + "wgpu-core-deps-windows", "wgpu-hal", "wgpu-naga-bridge", "wgpu-types", @@ -4741,6 +4742,13 @@ dependencies = [ "wgpu-hal", ] +[[package]] +name = "wgpu-core-deps-linux-android-bsd" +version = "30.0.0" +dependencies = [ + "wgpu-hal", +] + [[package]] name = "wgpu-core-deps-wasm" version = "30.0.0" @@ -4749,7 +4757,7 @@ dependencies = [ ] [[package]] -name = "wgpu-core-deps-windows-linux-android" +name = "wgpu-core-deps-windows" version = "30.0.0" dependencies = [ "wgpu-hal", diff --git a/Cargo.toml b/Cargo.toml index 53d7ff38e..1b0560c9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,7 +104,8 @@ wgpu-types = { version = "30.0.0", path = "./wgpu-types", default-features = fal # are allowed through though. hlsl-snapshots = { path = "naga/hlsl-snapshots" } -wgpu-core-deps-windows-linux-android = { version = "30.0.0", path = "./wgpu-core/platform-deps/windows-linux-android" } +wgpu-core-deps-linux-android-bsd = { version = "30.0.0", path = "./wgpu-core/platform-deps/linux-android-bsd" } +wgpu-core-deps-windows = { version = "30.0.0", path = "./wgpu-core/platform-deps/windows" } wgpu-core-deps-apple = { version = "30.0.0", path = "./wgpu-core/platform-deps/apple" } wgpu-core-deps-wasm = { version = "30.0.0", path = "./wgpu-core/platform-deps/wasm" } wgpu-core-deps-emscripten = { version = "30.0.0", path = "./wgpu-core/platform-deps/emscripten" } diff --git a/README.md b/README.md index a36c7b181..13a147701 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Contributors are welcome! See [CONTRIBUTING.md][contrib] for more information. ✅ = First Class Support 🆗 = Downlevel/Best Effort Support -📐 = Requires the [ANGLE](https://github.com/gfx-rs/wgpu/wiki/Running-on-ANGLE) translation layer (GL ES 3.0 only) +📐 = Requires the [ANGLE](https://github.com/gfx-rs/wgpu/wiki/Running-on-ANGLE) translation layer (GL ES 3.0 only). Use the `angle` feature on macOS/iOS. On Windows, `gles` uses WGL by default; build with `cfg(windows_angle)` to use ANGLE instead. 🌋 = Requires the [MoltenVK](https://vulkan.lunarg.com/sdk/home#mac) translation layer 🛠️ = Unsupported, though open to contributions diff --git a/docs/broadcast_license.nu b/docs/broadcast_license.nu index 4036dbaf7..3efbd9935 100644 --- a/docs/broadcast_license.nu +++ b/docs/broadcast_license.nu @@ -10,7 +10,8 @@ let crates = [ "wgpu-core/platform-deps/apple", "wgpu-core/platform-deps/emscripten", "wgpu-core/platform-deps/wasm", - "wgpu-core/platform-deps/windows-linux-android", + "wgpu-core/platform-deps/linux-android-bsd", + "wgpu-core/platform-deps/windows", "wgpu-hal", "wgpu-info", "wgpu-naga-bridge", diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 839f941b6..055b9d75f 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -130,28 +130,35 @@ portable-atomic = ["dep:portable-atomic", "wgpu-hal/portable-atomic"] # platform crates collude to provide platform-specific behavior. ## DX12 backend -dx12 = ["wgpu-core-deps-windows-linux-android/dx12"] +dx12 = ["wgpu-core-deps-windows/dx12"] ## Metal backend metal = ["wgpu-core-deps-apple/metal"] ## Vulkan backend, only available on Windows, Linux, Android -vulkan = ["wgpu-core-deps-windows-linux-android/vulkan"] +vulkan = [ + "wgpu-core-deps-linux-android-bsd/vulkan", + "wgpu-core-deps-windows/vulkan", +] ## OpenGL backend, only available on Windows, Linux, Android, and Emscripten gles = [ - "wgpu-core-deps-windows-linux-android/gles", + "wgpu-core-deps-linux-android-bsd/gles", + "wgpu-core-deps-windows/gles", "wgpu-core-deps-emscripten/gles", ] ## WebGL backend, only available on Emscripten webgl = ["wgpu-core-deps-wasm/webgl", "wgpu-types/web"] -## OpenGL backend, on macOS only +## OpenGL backend via ANGLE, only available on macOS angle = ["wgpu-core-deps-apple/angle"] ## Vulkan portability backend, only available on macOS vulkan-portability = ["wgpu-core-deps-apple/vulkan-portability"] ## Renderdoc integration, only available on Windows, Linux, and Android -renderdoc = ["wgpu-core-deps-windows-linux-android/renderdoc"] +renderdoc = [ + "wgpu-core-deps-linux-android-bsd/renderdoc", + "wgpu-core-deps-windows/renderdoc", +] ## Support creating textures from DRM display/window handles. -drm = ["wgpu-core-deps-windows-linux-android/drm"] +drm = ["wgpu-core-deps-windows/drm", "wgpu-core-deps-linux-android-bsd/drm"] ## Enable the `noop` backend. # TODO(https://github.com/gfx-rs/wgpu/issues/7120): there should be a hal feature @@ -169,8 +176,11 @@ wgpu-core-deps-emscripten = { workspace = true, optional = true } [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] wgpu-core-deps-wasm = { workspace = true, optional = true } -[target.'cfg(any(windows, target_os = "linux", target_os = "android", target_os = "freebsd"))'.dependencies] -wgpu-core-deps-windows-linux-android = { workspace = true, optional = true } +[target.'cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))'.dependencies] +wgpu-core-deps-linux-android-bsd = { workspace = true, optional = true } + +[target.'cfg(windows)'.dependencies] +wgpu-core-deps-windows = { workspace = true, optional = true } [dependencies] naga.workspace = true diff --git a/wgpu-core/platform-deps/apple/src/lib.rs b/wgpu-core/platform-deps/apple/src/lib.rs index 59fddaa92..7913c79d6 100644 --- a/wgpu-core/platform-deps/apple/src/lib.rs +++ b/wgpu-core/platform-deps/apple/src/lib.rs @@ -1,3 +1 @@ -//! This crate exists to allow platform and feature specific features work correctly. The features -//! enabled on this crate are only enabled on `target_vendor = "apple"` platforms. See wgpu-hal's `Cargo.toml` -//! for more information. +#![doc = include_str!("../README.md")] diff --git a/wgpu-core/platform-deps/emscripten/src/lib.rs b/wgpu-core/platform-deps/emscripten/src/lib.rs index d969cf885..7913c79d6 100644 --- a/wgpu-core/platform-deps/emscripten/src/lib.rs +++ b/wgpu-core/platform-deps/emscripten/src/lib.rs @@ -1,3 +1 @@ -//! This crate exists to allow platform and feature specific features work correctly. The features -//! enabled on this crate are only enabled on `target_os = "emscripten"` platforms. -//! See wgpu-hal's `Cargo.toml` for more information. +#![doc = include_str!("../README.md")] diff --git a/wgpu-core/platform-deps/linux-android-bsd/Cargo.toml b/wgpu-core/platform-deps/linux-android-bsd/Cargo.toml new file mode 100644 index 000000000..a1d2bd0fd --- /dev/null +++ b/wgpu-core/platform-deps/linux-android-bsd/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "wgpu-core-deps-linux-android-bsd" +version.workspace = true +authors.workspace = true +edition.workspace = true +description = "Feature unification helper crate for the Linux/Android/BSD platforms" +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true +readme = "README.md" + +# Override the workspace's `rust-version` key. Firefox uses `cargo vendor` to +# copy the crates it actually uses out of the workspace, so it's meaningful for +# them to have less restrictive MSRVs individually than the workspace as a +# whole, if their code permits. See `../README.md` for details. +rust-version = "1.76" + +[features] +gles = ["wgpu-hal/gles"] +vulkan = ["wgpu-hal/vulkan"] +renderdoc = ["wgpu-hal/renderdoc"] + +## Support creating textures from DRM display/window handles. +drm = ["wgpu-hal/drm"] + +# Depend on wgpu-hal conditionally, so that the above features only apply to wgpu-hal on this set of platforms. +[target.'cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "netbsd"))'.dependencies] +wgpu-hal.workspace = true diff --git a/wgpu-core/platform-deps/windows-linux-android/LICENSE.APACHE b/wgpu-core/platform-deps/linux-android-bsd/LICENSE.APACHE similarity index 100% rename from wgpu-core/platform-deps/windows-linux-android/LICENSE.APACHE rename to wgpu-core/platform-deps/linux-android-bsd/LICENSE.APACHE diff --git a/wgpu-core/platform-deps/windows-linux-android/LICENSE.MIT b/wgpu-core/platform-deps/linux-android-bsd/LICENSE.MIT similarity index 100% rename from wgpu-core/platform-deps/windows-linux-android/LICENSE.MIT rename to wgpu-core/platform-deps/linux-android-bsd/LICENSE.MIT diff --git a/wgpu-core/platform-deps/linux-android-bsd/README.md b/wgpu-core/platform-deps/linux-android-bsd/README.md new file mode 100644 index 000000000..bde87b078 --- /dev/null +++ b/wgpu-core/platform-deps/linux-android-bsd/README.md @@ -0,0 +1,3 @@ +This crate exists to allow platform and feature specific features work correctly. The features +enabled on this crate are only enabled on `target_os = "linux"`, `target_os = "android"` and +`target_os = "freebsd"` platforms. See wgpu-hal's `Cargo.toml` for more information. diff --git a/wgpu-core/platform-deps/linux-android-bsd/src/lib.rs b/wgpu-core/platform-deps/linux-android-bsd/src/lib.rs new file mode 100644 index 000000000..7913c79d6 --- /dev/null +++ b/wgpu-core/platform-deps/linux-android-bsd/src/lib.rs @@ -0,0 +1 @@ +#![doc = include_str!("../README.md")] diff --git a/wgpu-core/platform-deps/wasm/src/lib.rs b/wgpu-core/platform-deps/wasm/src/lib.rs index 6c03e6e5f..7913c79d6 100644 --- a/wgpu-core/platform-deps/wasm/src/lib.rs +++ b/wgpu-core/platform-deps/wasm/src/lib.rs @@ -1,3 +1 @@ -//! This crate exists to allow platform and feature specific features work correctly. The features -//! enabled on this crate are only enabled on `target_arch = "wasm32"` platforms. See wgpu-hal's `Cargo.toml` -//! for more information. +#![doc = include_str!("../README.md")] diff --git a/wgpu-core/platform-deps/windows-linux-android/README.md b/wgpu-core/platform-deps/windows-linux-android/README.md deleted file mode 100644 index fdc9f9d3a..000000000 --- a/wgpu-core/platform-deps/windows-linux-android/README.md +++ /dev/null @@ -1,3 +0,0 @@ -This crate exists to allow platform and feature specific features work correctly. The features -enabled on this crate are only enabled on `windows`, `target_os = "linux"`, and `target_os = "android"` -platforms. See wgpu-hal's `Cargo.toml` for more information. diff --git a/wgpu-core/platform-deps/windows-linux-android/src/lib.rs b/wgpu-core/platform-deps/windows-linux-android/src/lib.rs deleted file mode 100644 index 2b06dda01..000000000 --- a/wgpu-core/platform-deps/windows-linux-android/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! This crate exists to allow platform and feature specific features work correctly. The features -//! enabled on this crate are only enabled on `windows`, `target_os = "linux"`, and `target_os = "android"` -//! platforms. See wgpu-hal's `Cargo.toml` for more information. diff --git a/wgpu-core/platform-deps/windows-linux-android/Cargo.toml b/wgpu-core/platform-deps/windows/Cargo.toml similarity index 84% rename from wgpu-core/platform-deps/windows-linux-android/Cargo.toml rename to wgpu-core/platform-deps/windows/Cargo.toml index 4be34f6c5..5bb164174 100644 --- a/wgpu-core/platform-deps/windows-linux-android/Cargo.toml +++ b/wgpu-core/platform-deps/windows/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wgpu-core-deps-windows-linux-android" +name = "wgpu-core-deps-windows" version.workspace = true authors.workspace = true edition.workspace = true @@ -26,7 +26,7 @@ renderdoc = ["wgpu-hal/renderdoc"] drm = ["wgpu-hal/drm"] # Depend on wgpu-hal conditionally, so that the above features only apply to wgpu-hal on this set of platforms. -[target.'cfg(any(windows, target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "netbsd"))'.dependencies] +[target.'cfg(windows)'.dependencies] wgpu-hal.workspace = true [lints] diff --git a/wgpu-core/platform-deps/windows/LICENSE.APACHE b/wgpu-core/platform-deps/windows/LICENSE.APACHE new file mode 100644 index 000000000..d9a10c0d8 --- /dev/null +++ b/wgpu-core/platform-deps/windows/LICENSE.APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/wgpu-core/platform-deps/windows/LICENSE.MIT b/wgpu-core/platform-deps/windows/LICENSE.MIT new file mode 100644 index 000000000..8d02e4dbd --- /dev/null +++ b/wgpu-core/platform-deps/windows/LICENSE.MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 The gfx-rs developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/wgpu-core/platform-deps/windows/README.md b/wgpu-core/platform-deps/windows/README.md new file mode 100644 index 000000000..477919435 --- /dev/null +++ b/wgpu-core/platform-deps/windows/README.md @@ -0,0 +1,2 @@ +This crate exists to allow platform and feature specific features work correctly. The features +enabled on this crate are only enabled on `windows` platform. See wgpu-hal's `Cargo.toml` for more information. diff --git a/wgpu-core/platform-deps/windows/src/lib.rs b/wgpu-core/platform-deps/windows/src/lib.rs new file mode 100644 index 000000000..7913c79d6 --- /dev/null +++ b/wgpu-core/platform-deps/windows/src/lib.rs @@ -0,0 +1 @@ +#![doc = include_str!("../README.md")] diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index bd6fa8f18..3f62af0a4 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -38,6 +38,7 @@ missing_debug_implementations = "warn" unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(feature, values("cargo-clippy"))', # objc's `msg_send` macro injects this in our code https://github.com/SSheldon/rust-objc/issues/125 'cfg(web_sys_unstable_apis)', # web-sys uses this + 'cfg(windows_angle)', ] } [lib] @@ -58,7 +59,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ # wgpu-core's features are defined to enable the backends on their "default" platforms. For example we # exclude the Vulkan backend on MacOS unless a separate feature `vulkan-portability` is enabled. In response # to these features, it enables features of platform specific crates. For example, the `vulkan` feature in wgpu-core -# enables the `vulkan` feature in `wgpu-core-deps-windows-linux-android` which in turn enables the +# enables the `vulkan` feature in `wgpu-core-deps-linux-android-bsd` which in turn enables the # `vulkan` feature in `wgpu-hal` _only_ on those platforms. If you enable the `vulkan-portability` feature, it # will enable the `vulkan` feature in `wgpu-core-deps-apple`. The only way to do this is unfortunately to have # a separate crate for each platform category that participates in the feature unification. diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index eeb73694f..34e02e005 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -706,13 +706,6 @@ impl Instance { .expect("Could not lock instance. This is most-likely a deadlock.") .version } - - pub fn egl_config(&self) -> khronos_egl::Config { - self.inner - .try_lock() - .expect("Could not lock instance. This is most-likely a deadlock.") - .config - } } #[cfg(send_sync)] @@ -767,6 +760,31 @@ impl crate::Instance for Instance { let egl1_5: Option<&Arc> = Some(&egl); let (display, wsi_kind) = match (desc.display.map(|d| d.as_raw()), egl1_5) { + (Some(Rdh::Windows(_)) | None, Some(egl)) + if cfg!(windows) + && client_ext_str.contains("EGL_ANGLE_platform_angle") + && client_ext_str.contains("EGL_ANGLE_platform_angle_d3d") => + { + log::debug!("Using Angle platform with D3D11"); + const EGL_PLATFORM_ANGLE_TYPE_ANGLE: u32 = 0x3203; + const EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE: u32 = 0x3208; + let display_attributes = [ + EGL_PLATFORM_ANGLE_TYPE_ANGLE as khronos_egl::Attrib, + EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE as khronos_egl::Attrib, + EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED as khronos_egl::Attrib, + usize::from(desc.flags.contains(wgt::InstanceFlags::VALIDATION)), + khronos_egl::ATTRIB_NONE, + ]; + let display = unsafe { + egl.get_platform_display( + EGL_PLATFORM_ANGLE_ANGLE, + khronos_egl::DEFAULT_DISPLAY, + &display_attributes, + ) + } + .map_err(instance_err("failed to get Angle D3D11 display"))?; + (display, WindowKind::Unknown) + } (Some(Rdh::Wayland(wayland_display_handle)), Some(egl)) if client_ext_str.contains("EGL_EXT_platform_wayland") => { @@ -1083,7 +1101,7 @@ impl super::Device { #[derive(Debug)] pub struct Swapchain { surface: khronos_egl::Surface, - wl_window: Option<*mut wayland_sys::egl::wl_egl_window>, + wl_window: Option<*mut ffi::c_void>, framebuffer: glow::Framebuffer, renderbuffer: glow::Renderbuffer, /// Extent because the window lies @@ -1191,10 +1209,7 @@ impl Surface { unsafe fn unconfigure_impl( &self, device: &super::Device, - ) -> Option<( - khronos_egl::Surface, - Option<*mut wayland_sys::egl::wl_egl_window>, - )> { + ) -> Option<(khronos_egl::Surface, Option<*mut ffi::c_void>)> { let gl = &device.shared.context.lock(); match self.swapchain.write().take() { Some(sc) => { @@ -1226,11 +1241,12 @@ impl crate::Surface for Surface { let (surface, wl_window) = match unsafe { self.unconfigure_impl(device) } { Some((sc, wl_window)) => { + #[cfg(unix)] if let Some(window) = wl_window { wayland_sys::ffi_dispatch!( wayland_sys::egl::wayland_egl_handle(), wl_egl_window_resize, - window, + window.cast(), config.extent.width as i32, config.extent.height as i32, 0, @@ -1241,6 +1257,7 @@ impl crate::Surface for Surface { (sc, wl_window) } None => { + #[cfg_attr(not(unix), expect(unused_mut))] let mut wl_window = None; let (mut temp_xlib_handle, mut temp_xcb_handle); let native_window_ptr = match (self.wsi.kind, self.raw_window_handle) { @@ -1269,7 +1286,7 @@ impl crate::Surface for Surface { config.extent.width as i32, config.extent.height as i32, ); - wl_window = Some(window); + wl_window = Some(window.cast()); window.cast() } #[cfg(Emscripten)] @@ -1427,11 +1444,12 @@ impl crate::Surface for Surface { .instance .destroy_surface(self.egl.display, surface) .unwrap(); - if let Some(window) = wl_window { + if let Some(_window) = wl_window { + #[cfg(unix)] wayland_sys::ffi_dispatch!( wayland_sys::egl::wayland_egl_handle(), wl_egl_window_destroy, - window, + _window.cast(), ); } } diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 24e26c67e..dc502f225 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -1,7 +1,9 @@ /*! # OpenGL ES3 API (aka GLES3). -Designed to work on Linux and Android, with context provided by EGL. +Designed to work on platforms with context provided by EGL or WGL, including +Linux and Android via EGL, and Windows via WGL by default or ANGLE/EGL with +`cfg(windows_angle)`. ## Texture views @@ -79,40 +81,34 @@ we don't bother with that combination. */ -///cbindgen:ignore -#[cfg(not(any(windows, webgl)))] -mod egl; -#[cfg(Emscripten)] -mod emscripten; -#[cfg(webgl)] -mod web; -#[cfg(windows)] -mod wgl; - mod adapter; mod command; mod conv; mod device; +///cbindgen:ignore +#[cfg(all(not(webgl), any(not(windows), windows_angle)))] +mod egl; +#[cfg(all(not(webgl), any(not(windows), windows_angle)))] +pub use self::egl::{AdapterContext, AdapterContextLock, Instance, Surface}; + +#[cfg(Emscripten)] +mod emscripten; + mod fence; mod queue; +#[cfg(webgl)] +mod web; +#[cfg(webgl)] +pub use self::web::{AdapterContext, Instance, Surface}; + +#[cfg(all(windows, not(webgl), not(windows_angle)))] +mod wgl; +#[cfg(all(windows, not(webgl), not(windows_angle)))] +pub use self::wgl::{AdapterContext, AdapterContextLock, Instance, Surface}; + pub use fence::Fence; -#[cfg(not(any(windows, webgl)))] -pub use self::egl::{AdapterContext, AdapterContextLock}; -#[cfg(not(any(windows, webgl)))] -pub use self::egl::{Instance, Surface}; - -#[cfg(webgl)] -pub use self::web::AdapterContext; -#[cfg(webgl)] -pub use self::web::{Instance, Surface}; - -#[cfg(windows)] -use self::wgl::AdapterContext; -#[cfg(windows)] -pub use self::wgl::{Instance, Surface}; - use alloc::{boxed::Box, string::String, string::ToString as _, sync::Arc, vec::Vec}; use core::{ fmt, diff --git a/wgpu-types/src/backend.rs b/wgpu-types/src/backend.rs index 208a8bda9..091c538d0 100644 --- a/wgpu-types/src/backend.rs +++ b/wgpu-types/src/backend.rs @@ -97,8 +97,8 @@ bitflags::bitflags! { const VULKAN = 1 << Backend::Vulkan as u32; /// [`Backend::Gl`]. - /// Supported on Linux/Android, the web through webassembly via WebGL, and Windows and - /// macOS/iOS via ANGLE + /// Supported on Linux/Android, the web through webassembly via WebGL, and + /// Windows through native OpenGL by default or ANGLE with `cfg(windows_angle)`. const GL = 1 << Backend::Gl as u32; /// [`Backend::Metal`]. diff --git a/wgpu/build.rs b/wgpu/build.rs index 72d2b0be3..191566520 100644 --- a/wgpu/build.rs +++ b/wgpu/build.rs @@ -30,7 +30,7 @@ fn main() { // (Note that WebGL is also not included here!) all(any(windows, target_os = "linux", target_os = "android", target_os = "freebsd", Emscripten), feature = "gles"), // On Apple platforms, however, we require the `angle` feature to explicitly opt-in to OpenGL - // since its meant to be used with ANGLE. + // since it's meant to be used with ANGLE. all(target_vendor = "apple", feature = "angle") ) }, noop: { feature = "noop" },