From 883c7e71ae699a29c23b8f95b7335d015e5a985d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 25 Mar 2021 11:27:31 +0100 Subject: Introduce `internal_backend` to `iced_wgpu::Settings` --- wgpu/src/settings.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'wgpu/src/settings.rs') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 26763e22..abc404dc 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -16,6 +16,9 @@ pub struct Settings { /// [`Backend`]: crate::Backend pub present_mode: wgpu::PresentMode, + /// The internal graphics backend to use. + pub internal_backend: wgpu::BackendBit, + /// The bytes of the font that will be used by default. /// /// If `None` is provided, a default system font will be chosen. @@ -30,14 +33,52 @@ pub struct Settings { pub antialiasing: Option, } +impl Settings { + /// Creates new [`Settings`] using environment configuration. + /// + /// Specifically: + /// + /// - The `internal_backend` can be configured using the `WGPU_BACKEND` + /// environment variable. If the variable is not set, the primary backend + /// will be used. The following values are allowed: + /// - `vulkan` + /// - `metal` + /// - `dx12` + /// - `dx11` + /// - `gl` + /// - `webgpu` + pub fn from_env() -> Self { + Settings { + internal_backend: backend_from_env() + .unwrap_or(wgpu::BackendBit::PRIMARY), + ..Self::default() + } + } +} + impl Default for Settings { fn default() -> Settings { Settings { format: wgpu::TextureFormat::Bgra8UnormSrgb, present_mode: wgpu::PresentMode::Mailbox, + internal_backend: wgpu::BackendBit::PRIMARY, default_font: None, default_text_size: 20, antialiasing: None, } } } + +fn backend_from_env() -> Option { + std::env::var("WGPU_BACKEND").ok().map(|backend| { + match backend.to_lowercase().as_str() { + "vulkan" => wgpu::BackendBit::VULKAN, + "metal" => wgpu::BackendBit::METAL, + "dx12" => wgpu::BackendBit::DX12, + "dx11" => wgpu::BackendBit::DX11, + "gl" => wgpu::BackendBit::GL, + "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, + other => panic!("Unknown backend: {}", other), + } + }) +} -- cgit From e6db43987072e62ae146e9b6fe4bc2ef0e519073 Mon Sep 17 00:00:00 2001 From: Downtime Date: Thu, 13 May 2021 16:46:20 +0800 Subject: Add a primary backend that can be set Add a primary backend that can be set --- wgpu/src/settings.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'wgpu/src/settings.rs') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index abc404dc..4a1bb322 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -78,6 +78,7 @@ fn backend_from_env() -> Option { "dx11" => wgpu::BackendBit::DX11, "gl" => wgpu::BackendBit::GL, "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, + "primary" => wgpu::BackendBit::PRIMARY, other => panic!("Unknown backend: {}", other), } }) -- cgit From 88defb65caa70688c47a9d4d2d4f51dd97814e01 Mon Sep 17 00:00:00 2001 From: Downtime Date: Fri, 14 May 2021 21:21:25 +0800 Subject: update doc --- wgpu/src/settings.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'wgpu/src/settings.rs') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 4a1bb322..6c97d895 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -47,6 +47,7 @@ impl Settings { /// - `dx11` /// - `gl` /// - `webgpu` + /// - `primary` pub fn from_env() -> Self { Settings { internal_backend: backend_from_env() -- cgit From 217f5be8272f48a5b043d066ed1788cc127e1164 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 18:21:50 +0700 Subject: Add `text_multithreading` to `Settings` in `iced_glow` and `iced_wgpu` --- wgpu/src/settings.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'wgpu/src/settings.rs') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 6c97d895..b490e54e 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -29,6 +29,10 @@ pub struct Settings { /// By default, it will be set to 20. pub default_text_size: u16, + /// If enabled, spread text workload in multiple threads when multiple cores + /// are available. + pub text_multithreading: bool, + /// The antialiasing strategy that will be used for triangle primitives. pub antialiasing: Option, } @@ -65,6 +69,7 @@ impl Default for Settings { internal_backend: wgpu::BackendBit::PRIMARY, default_font: None, default_text_size: 20, + text_multithreading: false, antialiasing: None, } } -- cgit From 357a8a95c9820651110fe4d80d8d33a2678827c0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 18:27:33 +0700 Subject: Introduce `text_multithreading` to `Settings` --- wgpu/src/settings.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'wgpu/src/settings.rs') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index b490e54e..9a7eed34 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -31,9 +31,13 @@ pub struct Settings { /// If enabled, spread text workload in multiple threads when multiple cores /// are available. + /// + /// By default, it is disabled. pub text_multithreading: bool, /// The antialiasing strategy that will be used for triangle primitives. + /// + /// By default, it is `None`. pub antialiasing: Option, } -- cgit