Update the wgpu example runner to 0.19

This commit is contained in:
Fredrik Fornwall 2024-01-24 12:17:37 +01:00 committed by Eduard-Mihai Burtescu
parent f955221493
commit 1a9c8b8ba1
4 changed files with 271 additions and 323 deletions

523
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -21,14 +21,14 @@ cfg-if = "1.0.0"
shared = { path = "../../shaders/shared" }
futures = { version = "0.3", default-features = false, features = ["std", "executor"] }
# Vulkan SDK or MoltenVK needs to be installed for `vulkan-portability` to work on macOS
wgpu = { version = "0.18.0", features = ["spirv", "vulkan-portability"] }
wgpu = { version = "0.19.0", features = ["spirv", "vulkan-portability"] }
winit = { version = "0.29.0", features = ["android-native-activity", "rwh_05"] }
clap = { version = "4", features = ["derive"] }
strum = { version = "0.23.0", default_features = false, features = ["std", "derive"] }
strum = { version = "0.25.0", default_features = false, features = ["std", "derive"] }
bytemuck = "1.6.3"
[target.'cfg(not(any(target_os = "android", target_arch = "wasm32")))'.dependencies]
env_logger = "0.10.0"
env_logger = "0.11.0"
spirv-builder = { workspace = true, features = ["watch"] }
[target.'cfg(target_os = "android")'.dependencies]

View File

@ -22,18 +22,18 @@ async fn start_internal(options: &Options, compiled_shader_modules: CompiledShad
.await
.expect("Failed to find an appropriate adapter");
let mut features =
let mut required_features =
wgpu::Features::TIMESTAMP_QUERY | wgpu::Features::TIMESTAMP_QUERY_INSIDE_PASSES;
if options.force_spirv_passthru {
features |= wgpu::Features::SPIRV_SHADER_PASSTHROUGH;
required_features |= wgpu::Features::SPIRV_SHADER_PASSTHROUGH;
}
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features,
limits: wgpu::Limits::default(),
required_features,
required_limits: wgpu::Limits::default(),
},
None,
)

View File

@ -59,7 +59,8 @@ async fn run(
preferred_format: wgpu::TextureFormat::Rgba8UnormSrgb,
})
} else {
Ok(unsafe { instance.create_surface(&window) }
Ok(instance
.create_surface(&window)
.expect("Failed to create surface from window"))
};
@ -71,11 +72,11 @@ async fn run(
.await
.expect("Failed to find an appropriate adapter");
let mut features = wgpu::Features::PUSH_CONSTANTS;
let mut required_features = wgpu::Features::PUSH_CONSTANTS;
if options.force_spirv_passthru {
features |= wgpu::Features::SPIRV_SHADER_PASSTHROUGH;
required_features |= wgpu::Features::SPIRV_SHADER_PASSTHROUGH;
}
let limits = wgpu::Limits {
let required_limits = wgpu::Limits {
max_push_constant_size: 128,
..Default::default()
};
@ -85,16 +86,20 @@ async fn run(
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features,
limits,
required_features,
required_limits,
},
None,
)
.await
.expect("Failed to create device");
let auto_configure_surface =
|adapter: &_, device: &_, surface: wgpu::Surface, size: winit::dpi::PhysicalSize<_>| {
fn auto_configure_surface<'a>(
adapter: &wgpu::Adapter,
device: &wgpu::Device,
surface: wgpu::Surface<'a>,
size: winit::dpi::PhysicalSize<u32>,
) -> (wgpu::Surface<'a>, wgpu::SurfaceConfiguration) {
let mut surface_config = surface
.get_default_config(adapter, size.width, size.height)
.unwrap_or_else(|| {
@ -113,7 +118,7 @@ async fn run(
surface.configure(device, &surface_config);
(surface, surface_config)
};
}
let mut surface_with_config = initial_surface
.map(|surface| auto_configure_surface(&adapter, &device, surface, window.inner_size()));
@ -148,7 +153,7 @@ async fn run(
let mut mouse_button_press_since_last_frame = 0;
let mut mouse_button_press_time = [f32::NEG_INFINITY; 3];
event_loop.run(move |event, event_loop_window_target| {
event_loop.run(|event, event_loop_window_target| {
// Have the closure take ownership of the resources.
// `event_loop.run` never returns, therefore we must do this to ensure
// the resources are properly cleaned up.
@ -158,7 +163,7 @@ async fn run(
event_loop_window_target.set_control_flow(ControlFlow::Wait);
match event {
Event::Resumed => {
let new_surface = unsafe { instance.create_surface(&window) }
let new_surface = instance.create_surface(&window)
.expect("Failed to create surface from window (after resume)");
surface_with_config = Ok(auto_configure_surface(
&adapter,