From 455dd59b2c9c10b456a133302528775385e75810 Mon Sep 17 00:00:00 2001 From: Micha White Date: Sat, 4 Feb 2023 11:01:14 -0500 Subject: Upgrade to wgpu 0.15 --- alligator_render/Cargo.toml | 2 +- alligator_render/src/renderer.rs | 40 ++++++++++++++++++++++++++++++---------- alligator_render/src/texture.rs | 1 + 3 files changed, 32 insertions(+), 11 deletions(-) (limited to 'alligator_render') diff --git a/alligator_render/Cargo.toml b/alligator_render/Cargo.toml index 6de7b42..29940bb 100644 --- a/alligator_render/Cargo.toml +++ b/alligator_render/Cargo.toml @@ -9,7 +9,7 @@ rust-version = "1.65" [dependencies] winit = "0.27" log = "0.4" -wgpu = "0.14" +wgpu = "0.15" thiserror = "1" pollster = "0.2" bytemuck = { version = "1.4", features = ["derive"] } diff --git a/alligator_render/src/renderer.rs b/alligator_render/src/renderer.rs index 69035ae..98c772a 100644 --- a/alligator_render/src/renderer.rs +++ b/alligator_render/src/renderer.rs @@ -29,11 +29,28 @@ impl NoGpuError { } } +/// No device could be found which supports the given surface +#[derive(Clone, Copy, Debug, Error)] +#[error("A WebGPU or WebGL context could not be obtained")] +pub struct NoWebContextError { + /// Prevents this type from being constructed + _priv: (), +} + +impl NoWebContextError { + /// Create a new error + const fn new() -> Self { + Self { _priv: () } + } +} + #[derive(Debug, Error)] pub enum NewRendererError { #[error(transparent)] NoGpu(#[from] NoGpuError), #[error(transparent)] + NoWebContext(#[from] NoWebContextError), + #[error(transparent)] // TODO better error WindowInitError(#[from] OsError), } @@ -72,7 +89,7 @@ fn get_adapter( let adapter = adapter.or_else(|| { instance .enumerate_adapters(wgpu::Backends::PRIMARY) - .find(|adapter| !surface.get_supported_formats(adapter).is_empty()) + .find(|adapter| !surface.get_capabilities(adapter).formats.is_empty()) }); adapter.ok_or(NoGpuError::new()) @@ -136,10 +153,14 @@ impl Renderer { let event_loop = Some(event_loop); // the instance's main purpose is to create an adapter and a surface - let instance = wgpu::Instance::new(wgpu::Backends::VULKAN); + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::VULKAN, + dx12_shader_compiler: wgpu::Dx12Compiler::Fxc, // TODO support DXC + }); // the surface is the part of the screen we'll draw to - let surface = unsafe { instance.create_surface(&window) }; + let surface = + unsafe { instance.create_surface(&window) }.map_err(|_| NoWebContextError::new())?; let power_preference = config.power_preference(); @@ -160,16 +181,13 @@ impl Renderer { .expect("there was no device with the selected features"); // configuration for the surface - let supported_present_modes = surface - .get_supported_present_modes(&adapter) - .into_boxed_slice(); - let supported_alpha_modes = surface - .get_supported_alpha_modes(&adapter) - .into_boxed_slice(); + let capabilities = surface.get_capabilities(&adapter); + let supported_present_modes = capabilities.present_modes.into_boxed_slice(); + let supported_alpha_modes = capabilities.alpha_modes.into_boxed_slice(); let surface_config = config.to_surface_configuration( &supported_present_modes, &supported_alpha_modes, - surface.get_supported_formats(&adapter)[0], + capabilities.formats[0], ); surface.configure(&device, &surface_config); @@ -301,6 +319,7 @@ impl Renderer { /// A number of problems could occur here. A timeout could occur while /// trying to acquire the next frame. There may also be no more memory left /// that can be used for the new frame. + // TODO this needs to be smaller #[profiling::function] fn render(&mut self) -> Result<(), wgpu::SurfaceError> { // this will allow us to send commands to the gpu @@ -368,6 +387,7 @@ impl Renderer { } /// Run the renderer indefinitely + // TODO this needs to be smaller pub fn run(mut self, mut f: F) -> ! { self.window.set_visible(true); let event_loop = self.event_loop(); diff --git a/alligator_render/src/texture.rs b/alligator_render/src/texture.rs index 9f222e6..e2021f8 100644 --- a/alligator_render/src/texture.rs +++ b/alligator_render/src/texture.rs @@ -118,6 +118,7 @@ impl TextureAtlas { dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, + view_formats: &[wgpu::TextureFormat::Rgba8UnormSrgb], }); // TODO I don't think this refreshes anything -- cgit v1.2.3