Update wgpu and winit in the wgpu&ash example runners (#1112)

This commit is contained in:
Fredrik Fornwall 2024-01-03 10:12:48 +01:00 committed by GitHub
parent ed697bc192
commit 738974aa17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1290 additions and 768 deletions

View File

@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed 🛠 ### Changed 🛠
- [PR#1112](https://github.com/EmbarkStudios/rust-gpu/pull/1112) updated wgpu and winit in example runners
- [PR#1100](https://github.com/EmbarkStudios/rust-gpu/pull/1100) updated toolchain to `nightly-2023-09-30` - [PR#1100](https://github.com/EmbarkStudios/rust-gpu/pull/1100) updated toolchain to `nightly-2023-09-30`
- [PR#1091](https://github.com/EmbarkStudios/rust-gpu/pull/1091) updated toolchain to `nightly-2023-08-29` - [PR#1091](https://github.com/EmbarkStudios/rust-gpu/pull/1091) updated toolchain to `nightly-2023-08-29`
- [PR#1085](https://github.com/EmbarkStudios/rust-gpu/pull/1085) updated toolchain to `nightly-2023-07-08` - [PR#1085](https://github.com/EmbarkStudios/rust-gpu/pull/1085) updated toolchain to `nightly-2023-07-08`

1859
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ use-compiled-tools = ["spirv-builder/use-compiled-tools"]
ash = "0.37" ash = "0.37"
ash-window = "0.12" ash-window = "0.12"
raw-window-handle = "0.5.1" raw-window-handle = "0.5.1"
winit = "0.28.3" winit = { version = "0.29.0", features = ["rwh_05"] }
structopt = "0.3.20" structopt = "0.3.20"
cfg-if = "1.0.0" cfg-if = "1.0.0"
shared = { path = "../../shaders/shared" } shared = { path = "../../shaders/shared" }

View File

@ -78,7 +78,7 @@ use ash::{
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use winit::{ use winit::{
event::{Event, VirtualKeyCode, WindowEvent}, event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
}; };
@ -112,7 +112,7 @@ pub fn main() {
let shaders = compile_shaders(); let shaders = compile_shaders();
// runtime setup // runtime setup
let event_loop = EventLoop::new(); let event_loop = EventLoop::new().unwrap();
let window = winit::window::WindowBuilder::new() let window = winit::window::WindowBuilder::new()
.with_title("Rust GPU - ash") .with_title("Rust GPU - ash")
.with_inner_size(winit::dpi::LogicalSize::new( .with_inner_size(winit::dpi::LogicalSize::new(
@ -145,8 +145,9 @@ pub fn main() {
let (compiler_sender, compiler_reciever) = sync_channel(1); let (compiler_sender, compiler_reciever) = sync_channel(1);
event_loop.run(move |event, _window_target, control_flow| match event { event_loop
Event::RedrawEventsCleared { .. } => { .run(move |event, event_loop_window_target| match event {
Event::AboutToWait { .. } => {
match compiler_reciever.try_recv() { match compiler_reciever.try_recv() {
Err(TryRecvError::Empty) => { Err(TryRecvError::Empty) => {
if ctx.rendering_paused { if ctx.rendering_paused {
@ -172,9 +173,17 @@ pub fn main() {
}; };
} }
Event::WindowEvent { event, .. } => match event { Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode { WindowEvent::KeyboardInput {
Some(VirtualKeyCode::Escape) => *control_flow = ControlFlow::Exit, event:
Some(VirtualKeyCode::F5) => { winit::event::KeyEvent {
logical_key: winit::keyboard::Key::Named(key),
state: winit::event::ElementState::Pressed,
..
},
..
} => match key {
winit::keyboard::NamedKey::Escape => event_loop_window_target.exit(),
winit::keyboard::NamedKey::F5 => {
if !ctx.recompiling_shaders { if !ctx.recompiling_shaders {
ctx.recompiling_shaders = true; ctx.recompiling_shaders = true;
let compiler_sender = compiler_sender.clone(); let compiler_sender = compiler_sender.clone();
@ -187,10 +196,22 @@ pub fn main() {
}); });
} }
} }
Some(key @ (VirtualKeyCode::NumpadAdd | VirtualKeyCode::NumpadSubtract)) => { _ => {}
},
WindowEvent::KeyboardInput {
event:
winit::event::KeyEvent {
physical_key: winit::keyboard::PhysicalKey::Code(key_code),
state: winit::event::ElementState::Pressed,
..
},
..
} => match key_code {
winit::keyboard::KeyCode::NumpadAdd
| winit::keyboard::KeyCode::NumpadSubtract => {
let factor = let factor =
&mut ctx.sky_fs_spec_id_0x5007_sun_intensity_extra_spec_const_factor; &mut ctx.sky_fs_spec_id_0x5007_sun_intensity_extra_spec_const_factor;
*factor = if key == VirtualKeyCode::NumpadAdd { *factor = if key_code == winit::keyboard::KeyCode::NumpadAdd {
factor.saturating_add(1) factor.saturating_add(1)
} else { } else {
factor.saturating_sub(1) factor.saturating_sub(1)
@ -200,16 +221,17 @@ pub fn main() {
// shader module is needed (e.g. during pipeline rebuild). // shader module is needed (e.g. during pipeline rebuild).
ctx.rebuild_pipelines(vk::PipelineCache::null()); ctx.rebuild_pipelines(vk::PipelineCache::null());
} }
_ => *control_flow = ControlFlow::Wait, _ => {}
}, },
WindowEvent::Resized(_) => { WindowEvent::Resized(_) => {
ctx.recreate_swapchain(); ctx.recreate_swapchain();
} }
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, WindowEvent::CloseRequested => event_loop_window_target.exit(),
_ => *control_flow = ControlFlow::Wait, _ => {}
}, },
_ => *control_flow = ControlFlow::Wait, _ => event_loop_window_target.set_control_flow(ControlFlow::Wait),
}); })
.unwrap();
} }
pub fn compile_shaders() -> Vec<SpvFile> { pub fn compile_shaders() -> Vec<SpvFile> {

View File

@ -8,7 +8,7 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
minifb = "0.24.0" minifb = "0.25.0"
# bring in the shader as natively compiled code # bring in the shader as natively compiled code
shared = { path = "../../shaders/shared" } shared = { path = "../../shaders/shared" }
sky-shader = { path = "../../shaders/sky-shader" } sky-shader = { path = "../../shaders/sky-shader" }

View File

@ -21,8 +21,8 @@ cfg-if = "1.0.0"
shared = { path = "../../shaders/shared" } shared = { path = "../../shaders/shared" }
futures = { version = "0.3", default-features = false, features = ["std", "executor"] } 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 # Vulkan SDK or MoltenVK needs to be installed for `vulkan-portability` to work on macOS
wgpu = { version = "0.16.0", features = ["spirv", "vulkan-portability"] } wgpu = { version = "0.18.0", features = ["spirv", "vulkan-portability"] }
winit = { version = "0.28.3", features = ["android-native-activity"] } winit = { version = "0.29.0", features = ["android-native-activity", "rwh_05"] }
structopt = "0.3" structopt = "0.3"
strum = { version = "0.23.0", default_features = false, features = ["std", "derive"] } strum = { version = "0.23.0", default_features = false, features = ["std", "derive"] }
bytemuck = "1.6.3" bytemuck = "1.6.3"

View File

@ -16,8 +16,9 @@ async fn start_internal(options: &Options, compiled_shader_modules: CompiledShad
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends, backends,
dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(), dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(),
..Default::default()
}); });
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, None) let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, None)
.await .await
.expect("Failed to find an appropriate adapter"); .expect("Failed to find an appropriate adapter");
@ -142,7 +143,7 @@ async fn start_internal(options: &Options, compiled_shader_modules: CompiledShad
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{ {
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None }); let mut cpass = encoder.begin_compute_pass(&Default::default());
cpass.set_bind_group(0, &bind_group, &[]); cpass.set_bind_group(0, &bind_group, &[]);
cpass.set_pipeline(&compute_pipeline); cpass.set_pipeline(&compute_pipeline);
cpass.write_timestamp(&queries, 0); cpass.write_timestamp(&queries, 0);

View File

@ -2,7 +2,7 @@ use crate::{maybe_watch, CompiledShaderModules, Options};
use shared::ShaderConstants; use shared::ShaderConstants;
use winit::{ use winit::{
event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent}, event::{ElementState, Event, MouseButton, WindowEvent},
event_loop::{ControlFlow, EventLoop, EventLoopBuilder}, event_loop::{ControlFlow, EventLoop, EventLoopBuilder},
window::Window, window::Window,
}; };
@ -27,7 +27,9 @@ fn mouse_button_index(button: MouseButton) -> usize {
MouseButton::Left => 0, MouseButton::Left => 0,
MouseButton::Middle => 1, MouseButton::Middle => 1,
MouseButton::Right => 2, MouseButton::Right => 2,
MouseButton::Other(i) => 3 + (i as usize), MouseButton::Back => 3,
MouseButton::Forward => 4,
MouseButton::Other(i) => 5 + (i as usize),
} }
} }
@ -42,6 +44,7 @@ async fn run(
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends, backends,
dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(), dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(),
..Default::default()
}); });
// HACK(eddyb) marker error type for lazily-created surfaces (e.g. on Android). // HACK(eddyb) marker error type for lazily-created surfaces (e.g. on Android).
@ -62,7 +65,6 @@ async fn run(
let adapter = wgpu::util::initialize_adapter_from_env_or_default( let adapter = wgpu::util::initialize_adapter_from_env_or_default(
&instance, &instance,
backends,
// Request an adapter which can render to our surface // Request an adapter which can render to our surface
initial_surface.as_ref().ok(), initial_surface.as_ref().ok(),
) )
@ -146,18 +148,15 @@ async fn run(
let mut mouse_button_press_since_last_frame = 0; let mut mouse_button_press_since_last_frame = 0;
let mut mouse_button_press_time = [f32::NEG_INFINITY; 3]; let mut mouse_button_press_time = [f32::NEG_INFINITY; 3];
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, event_loop_window_target| {
// Have the closure take ownership of the resources. // Have the closure take ownership of the resources.
// `event_loop.run` never returns, therefore we must do this to ensure // `event_loop.run` never returns, therefore we must do this to ensure
// the resources are properly cleaned up. // the resources are properly cleaned up.
let _ = (&instance, &adapter, &pipeline_layout); let _ = (&instance, &adapter, &pipeline_layout);
let render_pipeline = &mut render_pipeline; let render_pipeline = &mut render_pipeline;
*control_flow = ControlFlow::Wait; event_loop_window_target.set_control_flow(ControlFlow::Wait);
match event { match event {
Event::MainEventsCleared => {
window.request_redraw();
}
Event::Resumed => { Event::Resumed => {
let new_surface = unsafe { instance.create_surface(&window) } let new_surface = unsafe { instance.create_surface(&window) }
.expect("Failed to create surface from window (after resume)"); .expect("Failed to create surface from window (after resume)");
@ -188,7 +187,10 @@ async fn run(
} }
} }
} }
Event::RedrawRequested(_) => { Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} => {
// FIXME(eddyb) only the mouse shader *really* needs this, could // FIXME(eddyb) only the mouse shader *really* needs this, could
// avoid doing wasteful rendering by special-casing each shader? // avoid doing wasteful rendering by special-casing each shader?
// (with VSync enabled this can't be *too* bad, thankfully) // (with VSync enabled this can't be *too* bad, thankfully)
@ -206,7 +208,7 @@ async fn run(
surface.configure(&device, surface_config); surface.configure(&device, surface_config);
} }
wgpu::SurfaceError::OutOfMemory => { wgpu::SurfaceError::OutOfMemory => {
*control_flow = ControlFlow::Exit; event_loop_window_target.exit();
} }
_ => (), _ => (),
} }
@ -226,10 +228,11 @@ async fn run(
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
store: true, store: wgpu::StoreOp::Store,
}, },
})], })],
depth_stencil_attachment: None, depth_stencil_attachment: None,
..Default::default()
}); });
let time = start.elapsed().as_secs_f32(); let time = start.elapsed().as_secs_f32();
@ -271,15 +274,17 @@ async fn run(
event: event:
WindowEvent::CloseRequested WindowEvent::CloseRequested
| WindowEvent::KeyboardInput { | WindowEvent::KeyboardInput {
input: event:
KeyboardInput { winit::event::KeyEvent {
virtual_keycode: Some(VirtualKeyCode::Escape), logical_key:
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
state: winit::event::ElementState::Pressed,
.. ..
}, },
.. ..
}, },
.. ..
} => *control_flow = ControlFlow::Exit, } => event_loop_window_target.exit(),
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::MouseInput { state, button, .. }, event: WindowEvent::MouseInput { state, button, .. },
.. ..
@ -323,11 +328,11 @@ async fn run(
new_module, new_module,
); );
window.request_redraw(); window.request_redraw();
*control_flow = ControlFlow::Poll; event_loop_window_target.set_control_flow(ControlFlow::Poll);
} }
_ => {} _ => {}
} }
}); }).unwrap();
} }
fn create_pipeline( fn create_pipeline(
@ -426,7 +431,7 @@ pub fn start(
env_logger::init(); env_logger::init();
} }
} }
let event_loop = event_loop_builder.build(); let event_loop = event_loop_builder.build().unwrap();
// Build the shader before we pop open a window, since it might take a while. // Build the shader before we pop open a window, since it might take a while.
let initial_shader = maybe_watch( let initial_shader = maybe_watch(