Use adapter limits (unless overridden) (#226)

- Fixes a regression caused by #223
- `downlevel_webgl2_defaults` only supports 2048x2048 pixels buffers
- This will allow pixel buffers up to the max supported by the hardware
This commit is contained in:
Jay Oster 2021-11-14 17:20:57 -08:00 committed by GitHub
parent 2a37e3ed1d
commit acd42495f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View file

@ -6,7 +6,7 @@ use raw_window_handle::HasRawWindowHandle;
/// A builder to help create customized pixel buffers. /// A builder to help create customized pixel buffers.
pub struct PixelsBuilder<'req, 'dev, 'win, W: HasRawWindowHandle> { pub struct PixelsBuilder<'req, 'dev, 'win, W: HasRawWindowHandle> {
request_adapter_options: Option<wgpu::RequestAdapterOptions<'req>>, request_adapter_options: Option<wgpu::RequestAdapterOptions<'req>>,
device_descriptor: wgpu::DeviceDescriptor<'dev>, device_descriptor: Option<wgpu::DeviceDescriptor<'dev>>,
backend: wgpu::Backends, backend: wgpu::Backends,
width: u32, width: u32,
height: u32, height: u32,
@ -46,10 +46,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'dev, 'win, W>
Self { Self {
request_adapter_options: None, request_adapter_options: None,
device_descriptor: wgpu::DeviceDescriptor { device_descriptor: None,
limits: wgpu::Limits::downlevel_webgl2_defaults(),
..wgpu::DeviceDescriptor::default()
},
backend: wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::PRIMARY), backend: wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::PRIMARY),
width, width,
height, height,
@ -72,7 +69,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'dev, 'win, W>
/// Add options for requesting a [`wgpu::Device`]. /// Add options for requesting a [`wgpu::Device`].
pub fn device_descriptor(mut self, device_descriptor: wgpu::DeviceDescriptor<'dev>) -> Self { pub fn device_descriptor(mut self, device_descriptor: wgpu::DeviceDescriptor<'dev>) -> Self {
self.device_descriptor = device_descriptor; self.device_descriptor = Some(device_descriptor);
self self
} }
@ -200,9 +197,15 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'dev, 'win, W>
}); });
let adapter = adapter.ok_or(Error::AdapterNotFound)?; let adapter = adapter.ok_or(Error::AdapterNotFound)?;
let (device, queue) = let device_descriptor = self
pollster::block_on(adapter.request_device(&self.device_descriptor, None)) .device_descriptor
.map_err(Error::DeviceNotFound)?; .unwrap_or_else(|| wgpu::DeviceDescriptor {
limits: adapter.limits(),
..wgpu::DeviceDescriptor::default()
});
let (device, queue) = pollster::block_on(adapter.request_device(&device_descriptor, None))
.map_err(Error::DeviceNotFound)?;
let present_mode = self.present_mode; let present_mode = self.present_mode;
let render_texture_format = self.render_texture_format.unwrap_or_else(|| { let render_texture_format = self.render_texture_format.unwrap_or_else(|| {

View file

@ -198,7 +198,7 @@ impl Pixels {
PixelsBuilder::new(width, height, surface_texture).build() PixelsBuilder::new(width, height, surface_texture).build()
} }
/// Resize the pixel buffer. /// Resize the pixel buffer and zero its contents.
/// ///
/// This does not resize the surface upon which the pixel buffer texture is rendered. Use /// This does not resize the surface upon which the pixel buffer texture is rendered. Use
/// [`Pixels::resize_surface`] to change the size of the surface texture. /// [`Pixels::resize_surface`] to change the size of the surface texture.