From 7779d682cf5fd6f28abc5b871e7819fbbdbb35eb Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Fri, 5 Jun 2020 02:20:17 -0700 Subject: [PATCH] Fix compatible_surface overrides when RequestAdapterOptions is provided (#85) - This will use the default `compatible_surface` from `SurfaceTexture` when `RequestAdapterOptions` is configured without `compatible_surface`. --- src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 38c58b0..eb4dacd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -557,13 +557,18 @@ impl<'req> PixelsBuilder<'req> { /// Returns an error when a [`wgpu::Adapter`] cannot be found. pub fn build(self) -> Result { // TODO: Use `options.pixel_aspect_ratio` to stretch the scaled texture + let compatible_surface = Some(&self.surface_texture.surface); let adapter = pollster::block_on(wgpu::Adapter::request( - &self - .request_adapter_options - .unwrap_or(wgpu::RequestAdapterOptions { - compatible_surface: Some(&self.surface_texture.surface), + &self.request_adapter_options.map_or_else( + || wgpu::RequestAdapterOptions { + compatible_surface, power_preference: wgpu::PowerPreference::Default, - }), + }, + |rao| wgpu::RequestAdapterOptions { + compatible_surface: rao.compatible_surface.or(compatible_surface), + power_preference: rao.power_preference, + }, + ), self.backend, )) .ok_or(Error::AdapterNotFound)?;