From 3840b75beaa3925f3438a7b40f01aaac221b8206 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Wed, 5 May 2021 14:33:03 +0700 Subject: Provide `compatible_surface` in `iced_wgpu::Compositor` --- wgpu/src/window/compositor.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index fdd648e8..aa873df8 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -21,9 +21,16 @@ impl Compositor { /// Requests a new [`Compositor`] with the given [`Settings`]. /// /// Returns `None` if no compatible graphics adapter could be found. - pub async fn request(settings: Settings) -> Option { + pub async fn request( + settings: Settings, + compatible_window: Option<&W>, + ) -> Option { let instance = wgpu::Instance::new(settings.internal_backend); + #[allow(unsafe_code)] + let compatible_surface = compatible_window + .map(|window| unsafe { instance.create_surface(window) }); + let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { @@ -31,7 +38,7 @@ impl Compositor { } else { wgpu::PowerPreference::HighPerformance }, - compatible_surface: None, + compatible_surface: compatible_surface.as_ref(), }) .await?; @@ -77,9 +84,15 @@ impl iced_graphics::window::Compositor for Compositor { type Surface = wgpu::Surface; type SwapChain = wgpu::SwapChain; - fn new(settings: Self::Settings) -> Result<(Self, Renderer), Error> { - let compositor = futures::executor::block_on(Self::request(settings)) - .ok_or(Error::AdapterNotFound)?; + fn new( + settings: Self::Settings, + compatible_window: Option<&W>, + ) -> Result<(Self, Renderer), Error> { + let compositor = futures::executor::block_on(Self::request( + settings, + compatible_window, + )) + .ok_or(Error::AdapterNotFound)?; let backend = compositor.create_backend(); -- cgit From 77a17cde83c9bdb8a61b871c7a15303f13e8d781 Mon Sep 17 00:00:00 2001 From: Zak Date: Tue, 11 May 2021 22:41:55 +0100 Subject: This commit optimizes the function used to converg rgba pixels into bgra pixels. --- wgpu/src/image/vector.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index ab0f67d0..8c7de617 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -1,7 +1,8 @@ -use crate::image::atlas::{self, Atlas}; use iced_native::svg; use std::collections::{HashMap, HashSet}; +use crate::image::atlas::{self, Atlas}; + pub enum Svg { Loaded(usvg::Tree), NotFound, @@ -111,26 +112,13 @@ impl Cache { let width = img.width(); let height = img.height(); - let mut rgba = img.take().into_iter(); - - // TODO: Perform conversion in the GPU - let bgra: Vec = std::iter::from_fn(move || { - use std::iter::once; - - let r = rgba.next()?; - let g = rgba.next()?; - let b = rgba.next()?; - let a = rgba.next()?; - - Some(once(b).chain(once(g)).chain(once(r)).chain(once(a))) - }) - .flatten() - .collect(); + let mut rgba = img.take(); + rgba.chunks_exact_mut(4).for_each(|rgba| rgba.swap(0, 2)); let allocation = texture_atlas.upload( width, height, - bytemuck::cast_slice(bgra.as_slice()), + bytemuck::cast_slice(rgba.as_slice()), device, encoder, )?; -- 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') 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') 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