mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-28 17:54:38 +00:00
Update wgpu and winit in the wgpu&ash example runners (#1112)
This commit is contained in:
parent
ed697bc192
commit
738974aa17
@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [Unreleased]
|
||||
|
||||
### 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#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`
|
||||
|
1859
Cargo.lock
generated
1859
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@ use-compiled-tools = ["spirv-builder/use-compiled-tools"]
|
||||
ash = "0.37"
|
||||
ash-window = "0.12"
|
||||
raw-window-handle = "0.5.1"
|
||||
winit = "0.28.3"
|
||||
winit = { version = "0.29.0", features = ["rwh_05"] }
|
||||
structopt = "0.3.20"
|
||||
cfg-if = "1.0.0"
|
||||
shared = { path = "../../shaders/shared" }
|
||||
|
@ -78,7 +78,7 @@ use ash::{
|
||||
|
||||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
||||
use winit::{
|
||||
event::{Event, VirtualKeyCode, WindowEvent},
|
||||
event::{Event, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
};
|
||||
|
||||
@ -112,7 +112,7 @@ pub fn main() {
|
||||
let shaders = compile_shaders();
|
||||
|
||||
// runtime setup
|
||||
let event_loop = EventLoop::new();
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let window = winit::window::WindowBuilder::new()
|
||||
.with_title("Rust GPU - ash")
|
||||
.with_inner_size(winit::dpi::LogicalSize::new(
|
||||
@ -145,8 +145,9 @@ pub fn main() {
|
||||
|
||||
let (compiler_sender, compiler_reciever) = sync_channel(1);
|
||||
|
||||
event_loop.run(move |event, _window_target, control_flow| match event {
|
||||
Event::RedrawEventsCleared { .. } => {
|
||||
event_loop
|
||||
.run(move |event, event_loop_window_target| match event {
|
||||
Event::AboutToWait { .. } => {
|
||||
match compiler_reciever.try_recv() {
|
||||
Err(TryRecvError::Empty) => {
|
||||
if ctx.rendering_paused {
|
||||
@ -172,9 +173,17 @@ pub fn main() {
|
||||
};
|
||||
}
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
|
||||
Some(VirtualKeyCode::Escape) => *control_flow = ControlFlow::Exit,
|
||||
Some(VirtualKeyCode::F5) => {
|
||||
WindowEvent::KeyboardInput {
|
||||
event:
|
||||
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 {
|
||||
ctx.recompiling_shaders = true;
|
||||
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 =
|
||||
&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)
|
||||
} else {
|
||||
factor.saturating_sub(1)
|
||||
@ -200,16 +221,17 @@ pub fn main() {
|
||||
// shader module is needed (e.g. during pipeline rebuild).
|
||||
ctx.rebuild_pipelines(vk::PipelineCache::null());
|
||||
}
|
||||
_ => *control_flow = ControlFlow::Wait,
|
||||
_ => {}
|
||||
},
|
||||
WindowEvent::Resized(_) => {
|
||||
ctx.recreate_swapchain();
|
||||
}
|
||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||
_ => *control_flow = ControlFlow::Wait,
|
||||
WindowEvent::CloseRequested => event_loop_window_target.exit(),
|
||||
_ => {}
|
||||
},
|
||||
_ => *control_flow = ControlFlow::Wait,
|
||||
});
|
||||
_ => event_loop_window_target.set_control_flow(ControlFlow::Wait),
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn compile_shaders() -> Vec<SpvFile> {
|
||||
|
@ -8,7 +8,7 @@ license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
minifb = "0.24.0"
|
||||
minifb = "0.25.0"
|
||||
# bring in the shader as natively compiled code
|
||||
shared = { path = "../../shaders/shared" }
|
||||
sky-shader = { path = "../../shaders/sky-shader" }
|
||||
|
@ -21,8 +21,8 @@ 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.16.0", features = ["spirv", "vulkan-portability"] }
|
||||
winit = { version = "0.28.3", features = ["android-native-activity"] }
|
||||
wgpu = { version = "0.18.0", features = ["spirv", "vulkan-portability"] }
|
||||
winit = { version = "0.29.0", features = ["android-native-activity", "rwh_05"] }
|
||||
structopt = "0.3"
|
||||
strum = { version = "0.23.0", default_features = false, features = ["std", "derive"] }
|
||||
bytemuck = "1.6.3"
|
||||
|
@ -16,8 +16,9 @@ async fn start_internal(options: &Options, compiled_shader_modules: CompiledShad
|
||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||
backends,
|
||||
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
|
||||
.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 });
|
||||
|
||||
{
|
||||
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_pipeline(&compute_pipeline);
|
||||
cpass.write_timestamp(&queries, 0);
|
||||
|
@ -2,7 +2,7 @@ use crate::{maybe_watch, CompiledShaderModules, Options};
|
||||
|
||||
use shared::ShaderConstants;
|
||||
use winit::{
|
||||
event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent},
|
||||
event::{ElementState, Event, MouseButton, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop, EventLoopBuilder},
|
||||
window::Window,
|
||||
};
|
||||
@ -27,7 +27,9 @@ fn mouse_button_index(button: MouseButton) -> usize {
|
||||
MouseButton::Left => 0,
|
||||
MouseButton::Middle => 1,
|
||||
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 {
|
||||
backends,
|
||||
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).
|
||||
@ -62,7 +65,6 @@ async fn run(
|
||||
|
||||
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
|
||||
&instance,
|
||||
backends,
|
||||
// Request an adapter which can render to our surface
|
||||
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_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.
|
||||
// `event_loop.run` never returns, therefore we must do this to ensure
|
||||
// the resources are properly cleaned up.
|
||||
let _ = (&instance, &adapter, &pipeline_layout);
|
||||
let render_pipeline = &mut render_pipeline;
|
||||
|
||||
*control_flow = ControlFlow::Wait;
|
||||
event_loop_window_target.set_control_flow(ControlFlow::Wait);
|
||||
match event {
|
||||
Event::MainEventsCleared => {
|
||||
window.request_redraw();
|
||||
}
|
||||
Event::Resumed => {
|
||||
let new_surface = unsafe { instance.create_surface(&window) }
|
||||
.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
|
||||
// avoid doing wasteful rendering by special-casing each shader?
|
||||
// (with VSync enabled this can't be *too* bad, thankfully)
|
||||
@ -206,7 +208,7 @@ async fn run(
|
||||
surface.configure(&device, surface_config);
|
||||
}
|
||||
wgpu::SurfaceError::OutOfMemory => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
event_loop_window_target.exit();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
@ -226,10 +228,11 @@ async fn run(
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
|
||||
store: true,
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let time = start.elapsed().as_secs_f32();
|
||||
@ -271,15 +274,17 @@ async fn run(
|
||||
event:
|
||||
WindowEvent::CloseRequested
|
||||
| WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
virtual_keycode: Some(VirtualKeyCode::Escape),
|
||||
event:
|
||||
winit::event::KeyEvent {
|
||||
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::MouseInput { state, button, .. },
|
||||
..
|
||||
@ -323,11 +328,11 @@ async fn run(
|
||||
new_module,
|
||||
);
|
||||
window.request_redraw();
|
||||
*control_flow = ControlFlow::Poll;
|
||||
event_loop_window_target.set_control_flow(ControlFlow::Poll);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}).unwrap();
|
||||
}
|
||||
|
||||
fn create_pipeline(
|
||||
@ -426,7 +431,7 @@ pub fn start(
|
||||
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.
|
||||
let initial_shader = maybe_watch(
|
||||
|
Loading…
Reference in New Issue
Block a user