Skip to content

Commit 9a4924f

Browse files
committed
wgpu: Added support for wgpu 27 with Skia
cc #9605
1 parent 5956546 commit 9a4924f

File tree

30 files changed

+1441
-26
lines changed

30 files changed

+1441
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ All notable changes to this project are documented in this file.
4040
- Minimum Supported Rust Version (MSRV) is 1.88
4141
- Slint macro: Use new Rust 1.88 API proc_macro API to be able to access file relative to the .rs file
4242
- Fixed error in generated Rust code when convering some expressions to void
43+
- Upgraded WGPU dependency to version 27: The `unstable-wgpu-27` Cargo feature exists next to the old `unstable-wgpu-26` feature,
44+
alongside the `slint::wgpu_27` module.
4345

4446
### Python
4547

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ unicode-segmentation = { version = "1.12.0" }
170170
glow = { version = "0.16" }
171171
tikv-jemallocator = { version = "0.6" }
172172
wgpu-26 = { package = "wgpu", version = "26", default-features = false }
173+
wgpu-27 = { package = "wgpu", version = "27", default-features = false }
173174
input = { version = "0.9.0", default-features = false }
174175
tr = { version = "0.1", default-features = false }
175176
fontique = { version = "0.5.0" }

api/cpp/cbindgen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ fn default_config() -> cbindgen::Config {
248248
("target_os = android".into(), "__ANDROID__".into()),
249249
// Disable Rust WGPU specific API feature
250250
("feature = unstable-wgpu-26".into(), "SLINT_DISABLED_CODE".into()),
251+
("feature = unstable-wgpu-27".into(), "SLINT_DISABLED_CODE".into()),
251252
]
252253
.iter()
253254
.cloned()

api/rs/slint/Cargo.toml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ backend-android-activity-05 = [
189189
"i-slint-backend-android-activity/aa-05",
190190
]
191191

192-
## Enable support for [WGPU](http://wgpu.rs) based rendering and expose WGPU based APIs based on WGPU version 25.x.
192+
## Enable support for [WGPU](http://wgpu.rs) based rendering and expose WGPU based APIs based on WGPU version 26.x.
193193
##
194194
## APIs guarded with this feature are *NOT* subject to the usual Slint API stability guarantees, because WGPU releases new major
195195
## versions frequently. This feature as well as the APIs changed or removed in future minor releases of Slint, likely to be replaced
@@ -199,7 +199,7 @@ backend-android-activity-05 = [
199199
## in your `Cargo.toml` when enabling this feature:
200200
##
201201
## ```toml
202-
## slint = { version = "~1.13", features = ["unstable-wgpu-26"] }
202+
## slint = { version = "~1.14", features = ["unstable-wgpu-26"] }
203203
## ```
204204
unstable-wgpu-26 = [
205205
"i-slint-core/unstable-wgpu-26",
@@ -208,6 +208,25 @@ unstable-wgpu-26 = [
208208
"dep:wgpu-26",
209209
]
210210

211+
## Enable support for [WGPU](http://wgpu.rs) based rendering and expose WGPU based APIs based on WGPU version 27.x.
212+
##
213+
## APIs guarded with this feature are *NOT* subject to the usual Slint API stability guarantees, because WGPU releases new major
214+
## versions frequently. This feature as well as the APIs changed or removed in future minor releases of Slint, likely to be replaced
215+
## by a feature with a similar name but the WGPU version suffix being bumped.
216+
##
217+
## To avoid unintended compilation failures, we recommend to use the [tilde requirement](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#tilde-requirements)
218+
## in your `Cargo.toml` when enabling this feature:
219+
##
220+
## ```toml
221+
## slint = { version = "~1.14", features = ["unstable-wgpu-27"] }
222+
## ```
223+
unstable-wgpu-27 = [
224+
"i-slint-core/unstable-wgpu-27",
225+
"i-slint-backend-selector/unstable-wgpu-27",
226+
"i-slint-backend-android-activity?/unstable-wgpu-27",
227+
"dep:wgpu-27",
228+
]
229+
211230
## APIs guarded with this feature are *NOT* subject to the usual Slint API stability guarantees, because winit releases new major
212231
## versions more frequently than Slint. This feature as well as the APIs changed or removed in future minor releases of Slint, likely to be replaced
213232
## by a feature with a similar name but the winit version suffix being bumped.
@@ -256,6 +275,7 @@ raw-window-handle-06 = { workspace = true, optional = true }
256275
unicode-segmentation = { workspace = true }
257276

258277
wgpu-26 = { workspace = true, optional = true }
278+
wgpu-27 = { workspace = true, optional = true }
259279

260280
i-slint-backend-winit = { workspace = true, optional = true }
261281

@@ -291,6 +311,7 @@ features = [
291311
"renderer-femtovg",
292312
"raw-window-handle-06",
293313
"unstable-wgpu-26",
314+
"unstable-wgpu-27",
294315
"unstable-winit-030",
295316
"unstable-libinput-09",
296317
]

api/rs/slint/lib.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,103 @@ pub mod wgpu_26 {
540540
pub use i_slint_core::graphics::wgpu_26::api::*;
541541
}
542542

543+
#[cfg(feature = "unstable-wgpu-27")]
544+
pub mod wgpu_27 {
545+
//! WGPU 27.x specific types and re-exports.
546+
//!
547+
//! *Note*: This module is behind a feature flag and may be removed or changed in future minor releases,
548+
//! as new major WGPU releases become available.
549+
//!
550+
//! Use the types in this module in combination with other APIs to integrate external, WGPU-based rendering engines
551+
//! into a UI with Slint.
552+
//!
553+
//! First, ensure that WGPU is used for rendering with Slint by using [`slint::BackendSelector::require_wgpu_26()`](i_slint_backend_selector::api::BackendSelector::require_wgpu_26()).
554+
//! This function accepts a pre-configured WGPU setup or configuration hints such as required features or memory limits.
555+
//!
556+
//! For rendering, it's crucial that you're using the same [`wgpu::Device`] and [`wgpu::Queue`] for allocating textures or submitting commands as Slint. Obtain the same queue
557+
//! by either using [`WGPUConfiguration::Manual`] to make Slint use an existing WGPU configuration, or use [`slint::Window::set_rendering_notifier()`](i_slint_core::api::Window::set_rendering_notifier())
558+
//! to let Slint invoke a callback that provides access device, queue, etc. in [`slint::GraphicsAPI::WGPU26`](i_slint_core::api::GraphicsAPI::WGPU26).
559+
//!
560+
//! To integrate rendering content into a scene shared with a Slint UI, use either [`slint::Window::set_rendering_notifier()`](i_slint_core::api::Window::set_rendering_notifier()) to render an underlay
561+
//! or overlay, or integrate externally produced [`wgpu::Texture`]s using [`slint::Image::try_from<wgpu::Texture>()`](i_slint_core::graphics::Image::try_from).
562+
//!
563+
//! The following example allocates a [`wgpu::Texture`] and, for the sake of simplicity in this documentation, fills with green as color, and then proceeds to set it as a `slint::Image` in the scene.
564+
//!
565+
//! `Cargo.toml`:
566+
//! ```toml
567+
//! slint = { version = "~1.14", features = ["unstable-wgpu-27"] }
568+
//! ```
569+
//!
570+
//! `main.rs`:
571+
//!```rust,no_run
572+
//!
573+
//! use slint::wgpu_27::wgpu;
574+
//! use wgpu::util::DeviceExt;
575+
//!
576+
//!slint::slint!{
577+
//! export component HelloWorld inherits Window {
578+
//! preferred-width: 320px;
579+
//! preferred-height: 300px;
580+
//! in-out property <image> app-texture;
581+
//! VerticalLayout {
582+
//! Text {
583+
//! text: "hello world";
584+
//! color: green;
585+
//! }
586+
//! Image { source: root.app-texture; }
587+
//! }
588+
//! }
589+
//!}
590+
//!fn main() -> Result<(), Box<dyn std::error::Error>> {
591+
//! slint::BackendSelector::new()
592+
//! .require_wgpu_27(slint::wgpu_27::WGPUConfiguration::default())
593+
//! .select()?;
594+
//! let app = HelloWorld::new()?;
595+
//!
596+
//! let app_weak = app.as_weak();
597+
//!
598+
//! app.window().set_rendering_notifier(move |state, graphics_api| {
599+
//! let (Some(app), slint::RenderingState::RenderingSetup, slint::GraphicsAPI::WGPU27{ device, queue, ..}) = (app_weak.upgrade(), state, graphics_api) else {
600+
//! return;
601+
//! };
602+
//!
603+
//! let mut pixels = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::new(320, 200);
604+
//! pixels.make_mut_slice().fill(slint::Rgba8Pixel {
605+
//! r: 0,
606+
//! g: 255,
607+
//! b :0,
608+
//! a: 255,
609+
//! });
610+
//!
611+
//! let texture = device.create_texture_with_data(queue,
612+
//! &wgpu::TextureDescriptor {
613+
//! label: None,
614+
//! size: wgpu::Extent3d { width: 320, height: 200, depth_or_array_layers: 1 },
615+
//! mip_level_count: 1,
616+
//! sample_count: 1,
617+
//! dimension: wgpu::TextureDimension::D2,
618+
//! format: wgpu::TextureFormat::Rgba8Unorm,
619+
//! usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
620+
//! view_formats: &[],
621+
//! },
622+
//! wgpu::util::TextureDataOrder::default(),
623+
//! pixels.as_bytes(),
624+
//! );
625+
//!
626+
//! let imported_image = slint::Image::try_from(texture).unwrap();
627+
//!
628+
//! app.set_app_texture(imported_image);
629+
//! })?;
630+
//!
631+
//! app.run()?;
632+
//!
633+
//! Ok(())
634+
//!}
635+
//!```
636+
//!
637+
pub use i_slint_core::graphics::wgpu_27::api::*;
638+
}
639+
543640
#[cfg(feature = "unstable-winit-030")]
544641
pub mod winit_030 {
545642
//! Winit 0.30.x specific types and re-exports.

examples/wgpu_texture/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ path = "main.rs"
1515
name = "wgpu_texture"
1616

1717
[dependencies]
18-
slint = { path = "../../api/rs/slint", features = ["unstable-wgpu-26"] }
18+
slint = { path = "../../api/rs/slint", features = ["unstable-wgpu-27"] }
1919
bytemuck = { workspace = true }
20+
wgpu-27 = { workspace = true, features = ["wgsl"] }
2021

2122
[build-dependencies]
2223
slint-build = { path = "../../api/rs/build" }

examples/wgpu_texture/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
slint::include_modules!();
55

6-
use slint::wgpu_26::{wgpu, WGPUConfiguration, WGPUSettings};
6+
use slint::wgpu_27::{wgpu, WGPUConfiguration, WGPUSettings};
77

88
struct DemoRenderer {
99
device: wgpu::Device,
@@ -146,7 +146,7 @@ fn main() {
146146
wgpu_settings.device_required_limits.max_push_constant_size = 16;
147147

148148
slint::BackendSelector::new()
149-
.require_wgpu_26(WGPUConfiguration::Automatic(wgpu_settings))
149+
.require_wgpu_27(WGPUConfiguration::Automatic(wgpu_settings))
150150
.select()
151151
.expect("Unable to create Slint backend with WGPU based renderer");
152152

@@ -163,7 +163,7 @@ fn main() {
163163
match state {
164164
slint::RenderingState::RenderingSetup => {
165165
match graphics_api {
166-
slint::GraphicsAPI::WGPU26 { device, queue, .. } => {
166+
slint::GraphicsAPI::WGPU27 { device, queue, .. } => {
167167
underlay = Some(DemoRenderer::new(device, queue));
168168
}
169169
_ => return,

internal/backends/android-activity/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ native-activity = ["android-activity-06?/native-activity", "android-activity-05?
2121
aa-06 = ["android-activity-06", "ndk-09"]
2222
aa-05 = ["android-activity-05", "ndk-08"]
2323
unstable-wgpu-26 = ["i-slint-renderer-skia/unstable-wgpu-26"]
24+
unstable-wgpu-27 = ["i-slint-renderer-skia/unstable-wgpu-27"]
2425

2526
[target.'cfg(target_os = "android")'.dependencies]
2627
i-slint-renderer-skia = { workspace = true }

internal/backends/selector/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ unstable-wgpu-26 = [
5656
"i-slint-backend-winit?/unstable-wgpu-26",
5757
]
5858

59+
unstable-wgpu-27 = [
60+
"i-slint-core/unstable-wgpu-27",
61+
"i-slint-renderer-skia?/unstable-wgpu-27",
62+
"i-slint-backend-winit?/unstable-wgpu-27",
63+
]
64+
5965
unstable-winit-030 = ["i-slint-backend-winit"]
6066

6167
unstable-libinput-09 = ["dep:input"]

internal/backends/selector/api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ impl BackendSelector {
129129
self
130130
}
131131

132+
#[i_slint_core_macros::slint_doc]
133+
/// Adds the requirement to the selector that the backend must render using [WGPU](http://wgpu.rs).
134+
/// Use this when you integrate other WGPU-based renderers with a Slint UI.
135+
///
136+
/// *Note*: This function is behind the [`unstable-wgpu-27` feature flag](slint:rust:slint/docs/cargo_features/#backends)
137+
/// and may be removed or changed in future minor releases, as new major WGPU releases become available.
138+
///
139+
/// See also the [`slint::wgpu_27`](slint:rust:slint/wgpu_27) module.
140+
#[cfg(feature = "unstable-wgpu-27")]
141+
#[must_use]
142+
pub fn require_wgpu_27(
143+
mut self,
144+
configuration: i_slint_core::graphics::wgpu_27::api::WGPUConfiguration,
145+
) -> Self {
146+
self.requested_graphics_api = Some(RequestedGraphicsAPI::WGPU27(configuration));
147+
self
148+
}
149+
132150
#[i_slint_core_macros::slint_doc]
133151
/// Configures this builder to use the specified winit hook that will be called before a Window is created.
134152
///

0 commit comments

Comments
 (0)