Skip to content

Commit 9cebd7f

Browse files
committed
Update to wgpu-0.19
1 parent 74e61d5 commit 9cebd7f

File tree

16 files changed

+860
-536
lines changed

16 files changed

+860
-536
lines changed

Cargo.lock

Lines changed: 681 additions & 381 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ default-run = "road"
88
publish = false
99

1010
[workspace]
11-
members = [
12-
"lib/ffi",
13-
"lib/m3d",
14-
"lib/splay",
15-
"lib/tiff",
16-
]
11+
members = ["lib/ffi", "lib/m3d", "lib/splay", "lib/tiff"]
1712

1813
[lib]
1914

@@ -61,20 +56,20 @@ serde = "1.0"
6156
serde_derive = "1.0"
6257
serde_scan = "0.4"
6358
# keep in sync with `lib/ffi/Cargo.toml`
64-
wgpu = { version = "0.17", features = [] }
59+
wgpu = { version = "0.19", features = [] }
6560
# binaries
6661
env_logger = "0.10"
6762
getopts = "0.2"
6863
obj = "0.10"
6964
png = "0.17"
70-
winit = "0.28"
65+
winit = "0.29"
7166
# gui
72-
egui = "0.22"
73-
egui_winit_platform = "0.19"
74-
egui_wgpu_backend = "0.25"
67+
egui = "0.26"
68+
egui_winit_platform = "0.21"
69+
egui_wgpu_backend = "0.28"
7570

7671
[dev-dependencies]
77-
naga = { version = "0.13", features = ["wgsl-in", "validate"] }
72+
naga = { version = "0.19", features = ["wgsl-in"] }
7873

7974
[dependencies.profiling]
8075
version = "1.0.1"

bin/boilerplate.rs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#![allow(clippy::single_match)]
22
use vangers::{
3-
config::{settings::Terrain, Settings},
3+
config::Settings,
44
render::{GraphicsContext, ScreenTargets, DEPTH_FORMAT},
55
};
66

77
use futures::executor::LocalPool;
88
use log::info;
99
use winit::{
1010
event,
11-
event_loop::{ControlFlow, EventLoop},
11+
event_loop::EventLoop,
1212
window::{Window, WindowBuilder},
1313
};
1414

1515
pub trait Application {
16-
fn on_key(&mut self, input: event::KeyboardInput) -> bool;
16+
fn on_key(&mut self, input: event::KeyEvent, modifiers: event::Modifiers) -> bool;
1717
fn on_mouse_wheel(&mut self, _delta: event::MouseScrollDelta) {}
1818
fn on_cursor_move(&mut self, _position: (f64, f64)) {}
1919
fn on_mouse_button(&mut self, _state: event::ElementState, _button: event::MouseButton) {}
@@ -24,28 +24,27 @@ pub trait Application {
2424
fn draw(&mut self, device: &wgpu::Device, targets: ScreenTargets) -> wgpu::CommandBuffer;
2525
}
2626

27-
struct WindowContext {
27+
struct WindowContext<'a> {
2828
window: Window,
2929
task_pool: LocalPool,
30-
surface: wgpu::Surface,
30+
surface: wgpu::Surface<'a>,
3131
present_mode: wgpu::PresentMode,
3232
reload_on_focus: bool,
3333
egui_platform: egui_winit_platform::Platform,
3434
depth_target: wgpu::TextureView,
3535
}
3636

37-
pub struct Harness {
37+
pub struct Harness<'a> {
3838
event_loop: EventLoop<()>,
39-
window_ctx: WindowContext,
39+
window_ctx: WindowContext<'a>,
4040
pub graphics_ctx: GraphicsContext,
4141
}
4242

4343
pub struct HarnessOptions {
4444
pub title: &'static str,
45-
pub uses_level: bool,
4645
}
4746

48-
impl Harness {
47+
impl Harness<'_> {
4948
pub fn init(options: HarnessOptions) -> (Self, Settings) {
5049
env_logger::init();
5150
let mut task_pool = LocalPool::new();
@@ -61,17 +60,22 @@ impl Harness {
6160
info!("Initializing the window");
6261
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
6362
backends: settings.backend.to_wgpu(),
63+
gles_minor_version: wgpu::Gles3MinorVersion::Automatic,
6464
..Default::default()
6565
});
66-
let event_loop = EventLoop::new();
66+
let event_loop = EventLoop::new().unwrap();
6767
let window = WindowBuilder::new()
6868
.with_title(options.title)
6969
.with_inner_size(winit::dpi::PhysicalSize::new(extent.width, extent.height))
7070
.with_resizable(true)
7171
.build(&event_loop)
7272
.unwrap();
73-
let surface =
74-
unsafe { instance.create_surface(&window) }.expect("Unable to create surface.");
73+
74+
//TODO: use safe `create_surface`. Problematic given our return type.
75+
let surface = unsafe {
76+
instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap())
77+
}
78+
.expect("Unable to create surface.");
7579

7680
info!("Initializing the device");
7781
let adapter = task_pool
@@ -83,14 +87,16 @@ impl Harness {
8387
.expect("Unable to initialize GPU via the selected backend.");
8488

8589
let downlevel_caps = adapter.get_downlevel_capabilities();
86-
let limits = settings.render.get_device_limits(&adapter.limits());
90+
let required_limits = settings
91+
.render
92+
.get_device_limits(&adapter.limits(), settings.game.geometry.height);
8793

8894
let (device, queue) = task_pool
8995
.run_until(adapter.request_device(
9096
&wgpu::DeviceDescriptor {
9197
label: None,
92-
features: wgpu::Features::empty(),
93-
limits,
98+
required_features: wgpu::Features::empty(),
99+
required_limits,
94100
},
95101
if settings.render.wgpu_trace_path.is_empty() {
96102
None
@@ -123,6 +129,7 @@ impl Harness {
123129
present_mode,
124130
alpha_mode: wgpu::CompositeAlphaMode::Auto,
125131
view_formats: Vec::new(),
132+
desired_maximum_frame_latency: 1,
126133
};
127134
surface.configure(&device, &config);
128135

@@ -177,6 +184,7 @@ impl Harness {
177184
let start_time = time::Instant::now();
178185
let mut last_time = time::Instant::now();
179186
let mut needs_reload = false;
187+
let mut modifiers = event::Modifiers::default();
180188
let Harness {
181189
event_loop,
182190
window_ctx: mut win,
@@ -185,9 +193,8 @@ impl Harness {
185193

186194
let mut egui_pass = egui_wgpu_backend::RenderPass::new(&gfx.device, gfx.color_format, 1);
187195

188-
event_loop.run(move |event, _, control_flow| {
196+
let _ = event_loop.run(move |event, target_window| {
189197
let _ = win.window;
190-
*control_flow = ControlFlow::Poll;
191198
win.task_pool.run_until_stalled();
192199

193200
win.egui_platform.handle_event(&event);
@@ -214,6 +221,7 @@ impl Harness {
214221
present_mode: win.present_mode,
215222
alpha_mode: wgpu::CompositeAlphaMode::Auto,
216223
view_formats: Vec::new(),
224+
desired_maximum_frame_latency: 1,
217225
};
218226
win.surface.configure(&gfx.device, &config);
219227
win.depth_target = gfx
@@ -241,11 +249,14 @@ impl Harness {
241249
needs_reload = false;
242250
}
243251
event::WindowEvent::CloseRequested => {
244-
*control_flow = ControlFlow::Exit;
252+
target_window.exit();
253+
}
254+
event::WindowEvent::ModifiersChanged(mods) => {
255+
modifiers = mods;
245256
}
246-
event::WindowEvent::KeyboardInput { input, .. } => {
247-
if !app.on_key(input) {
248-
*control_flow = ControlFlow::Exit;
257+
event::WindowEvent::KeyboardInput { event, .. } => {
258+
if !app.on_key(event, modifiers) {
259+
target_window.exit();
249260
}
250261
}
251262
event::WindowEvent::MouseWheel { delta, .. } => app.on_mouse_wheel(delta),
@@ -257,7 +268,7 @@ impl Harness {
257268
}
258269
_ => {}
259270
},
260-
event::Event::MainEventsCleared => {
271+
event::Event::AboutToWait => {
261272
let duration = time::Instant::now() - last_time;
262273
last_time += duration;
263274

@@ -274,8 +285,10 @@ impl Harness {
274285
app.draw_ui(&win.egui_platform.context());
275286
let egui_output = win.egui_platform.end_frame(Some(&win.window));
276287

277-
let egui_primitives =
278-
win.egui_platform.context().tessellate(egui_output.shapes);
288+
let egui_primitives = win
289+
.egui_platform
290+
.context()
291+
.tessellate(egui_output.shapes, 1.0);
279292
let screen_descriptor = egui_wgpu_backend::ScreenDescriptor {
280293
physical_width: gfx.screen_size.width,
281294
physical_height: gfx.screen_size.height,

bin/level/app.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -191,69 +191,78 @@ impl Application for LevelView {
191191
}
192192
}
193193

194-
fn on_key(&mut self, input: event::KeyboardInput) -> bool {
195-
use winit::event::{ElementState, KeyboardInput, VirtualKeyCode as Key};
194+
fn on_key(&mut self, input: event::KeyEvent, modifiers: event::Modifiers) -> bool {
195+
use winit::{
196+
event::ElementState,
197+
keyboard::{KeyCode, ModifiersKeyState, PhysicalKey},
198+
};
196199

197200
let i = &mut self.input;
201+
let alt = modifiers.lalt_state() == ModifiersKeyState::Pressed;
202+
let shift = modifiers.lshift_state() == ModifiersKeyState::Pressed;
198203
#[allow(deprecated)]
199204
match input {
200-
KeyboardInput {
205+
event::KeyEvent {
201206
state: ElementState::Pressed,
202-
virtual_keycode: Some(key),
203-
ref modifiers,
207+
physical_key: PhysicalKey::Code(key),
204208
..
205209
} => match key {
206-
Key::Escape => return false,
207-
Key::W => {
210+
KeyCode::Escape => return false,
211+
KeyCode::KeyW => {
208212
*i = Input::Ver {
209213
dir: self.cam.scale.y,
210-
alt: modifiers.alt(),
211-
shift: modifiers.shift(),
214+
alt,
215+
shift,
212216
}
213217
}
214-
Key::S => {
218+
KeyCode::KeyS => {
215219
*i = Input::Ver {
216220
dir: -self.cam.scale.y,
217-
alt: modifiers.alt(),
218-
shift: modifiers.shift(),
221+
alt,
222+
shift,
219223
}
220224
}
221-
Key::A => {
225+
KeyCode::KeyA => {
222226
*i = Input::Hor {
223227
dir: -self.cam.scale.x,
224-
alt: modifiers.alt(),
225-
shift: modifiers.shift(),
228+
alt,
229+
shift,
226230
}
227231
}
228-
Key::D => {
232+
KeyCode::KeyD => {
229233
*i = Input::Hor {
230234
dir: self.cam.scale.x,
231-
alt: modifiers.alt(),
232-
shift: modifiers.shift(),
235+
alt,
236+
shift,
233237
}
234238
}
235-
Key::Z => {
239+
KeyCode::KeyZ => {
236240
*i = Input::Dep {
237241
dir: -self.cam.scale.z,
238-
alt: modifiers.alt(),
242+
alt,
239243
}
240244
}
241-
Key::X => {
245+
KeyCode::KeyX => {
242246
*i = Input::Dep {
243247
dir: self.cam.scale.z,
244-
alt: modifiers.alt(),
248+
alt,
245249
}
246250
}
247-
Key::LAlt => self.alt_button_pressed = true,
251+
KeyCode::AltLeft => self.alt_button_pressed = true,
248252
_ => (),
249253
},
250-
KeyboardInput {
254+
event::KeyEvent {
251255
state: ElementState::Released,
252-
virtual_keycode: Some(key),
256+
physical_key: PhysicalKey::Code(key),
253257
..
254258
} => match key {
255-
Key::W | Key::S | Key::A | Key::D | Key::Z | Key::X => *i = Input::Empty,
256-
Key::LAlt => self.alt_button_pressed = false,
259+
KeyCode::KeyW
260+
| KeyCode::KeyS
261+
| KeyCode::KeyA
262+
| KeyCode::KeyD
263+
| KeyCode::KeyZ
264+
| KeyCode::KeyX => *i = Input::Empty,
265+
KeyCode::AltLeft => self.alt_button_pressed = false,
257266
_ => (),
258267
},
259268
/*

bin/level/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ mod boilerplate;
55
fn main() {
66
use std::env;
77

8-
let (harness, settings) = boilerplate::Harness::init(boilerplate::HarnessOptions {
9-
title: "level",
10-
uses_level: true,
11-
});
8+
let (harness, settings) =
9+
boilerplate::Harness::init(boilerplate::HarnessOptions { title: "level" });
1210

1311
let args: Vec<_> = env::args().collect();
1412
let mut options = getopts::Options::new();

0 commit comments

Comments
 (0)