Skip to content

Commit

Permalink
Update to wgpu-0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Oct 23, 2024
1 parent 74e61d5 commit 9cebd7f
Show file tree
Hide file tree
Showing 16 changed files with 860 additions and 536 deletions.
1,062 changes: 681 additions & 381 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ default-run = "road"
publish = false

[workspace]
members = [
"lib/ffi",
"lib/m3d",
"lib/splay",
"lib/tiff",
]
members = ["lib/ffi", "lib/m3d", "lib/splay", "lib/tiff"]

[lib]

Expand Down Expand Up @@ -61,20 +56,20 @@ serde = "1.0"
serde_derive = "1.0"
serde_scan = "0.4"
# keep in sync with `lib/ffi/Cargo.toml`
wgpu = { version = "0.17", features = [] }
wgpu = { version = "0.19", features = [] }
# binaries
env_logger = "0.10"
getopts = "0.2"
obj = "0.10"
png = "0.17"
winit = "0.28"
winit = "0.29"
# gui
egui = "0.22"
egui_winit_platform = "0.19"
egui_wgpu_backend = "0.25"
egui = "0.26"
egui_winit_platform = "0.21"
egui_wgpu_backend = "0.28"

[dev-dependencies]
naga = { version = "0.13", features = ["wgsl-in", "validate"] }
naga = { version = "0.19", features = ["wgsl-in"] }

[dependencies.profiling]
version = "1.0.1"
Expand Down
61 changes: 37 additions & 24 deletions bin/boilerplate.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#![allow(clippy::single_match)]
use vangers::{
config::{settings::Terrain, Settings},
config::Settings,
render::{GraphicsContext, ScreenTargets, DEPTH_FORMAT},
};

use futures::executor::LocalPool;
use log::info;
use winit::{
event,
event_loop::{ControlFlow, EventLoop},
event_loop::EventLoop,
window::{Window, WindowBuilder},
};

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

struct WindowContext {
struct WindowContext<'a> {
window: Window,
task_pool: LocalPool,
surface: wgpu::Surface,
surface: wgpu::Surface<'a>,
present_mode: wgpu::PresentMode,
reload_on_focus: bool,
egui_platform: egui_winit_platform::Platform,
depth_target: wgpu::TextureView,
}

pub struct Harness {
pub struct Harness<'a> {
event_loop: EventLoop<()>,
window_ctx: WindowContext,
window_ctx: WindowContext<'a>,
pub graphics_ctx: GraphicsContext,
}

pub struct HarnessOptions {
pub title: &'static str,
pub uses_level: bool,
}

impl Harness {
impl Harness<'_> {
pub fn init(options: HarnessOptions) -> (Self, Settings) {
env_logger::init();
let mut task_pool = LocalPool::new();
Expand All @@ -61,17 +60,22 @@ impl Harness {
info!("Initializing the window");
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: settings.backend.to_wgpu(),
gles_minor_version: wgpu::Gles3MinorVersion::Automatic,
..Default::default()
});
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new()
.with_title(options.title)
.with_inner_size(winit::dpi::PhysicalSize::new(extent.width, extent.height))
.with_resizable(true)
.build(&event_loop)
.unwrap();
let surface =
unsafe { instance.create_surface(&window) }.expect("Unable to create surface.");

//TODO: use safe `create_surface`. Problematic given our return type.
let surface = unsafe {
instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap())
}
.expect("Unable to create surface.");

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

let downlevel_caps = adapter.get_downlevel_capabilities();
let limits = settings.render.get_device_limits(&adapter.limits());
let required_limits = settings
.render
.get_device_limits(&adapter.limits(), settings.game.geometry.height);

let (device, queue) = task_pool
.run_until(adapter.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
limits,
required_features: wgpu::Features::empty(),
required_limits,
},
if settings.render.wgpu_trace_path.is_empty() {
None
Expand Down Expand Up @@ -123,6 +129,7 @@ impl Harness {
present_mode,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: Vec::new(),
desired_maximum_frame_latency: 1,
};
surface.configure(&device, &config);

Expand Down Expand Up @@ -177,6 +184,7 @@ impl Harness {
let start_time = time::Instant::now();
let mut last_time = time::Instant::now();
let mut needs_reload = false;
let mut modifiers = event::Modifiers::default();
let Harness {
event_loop,
window_ctx: mut win,
Expand All @@ -185,9 +193,8 @@ impl Harness {

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

event_loop.run(move |event, _, control_flow| {
let _ = event_loop.run(move |event, target_window| {
let _ = win.window;
*control_flow = ControlFlow::Poll;
win.task_pool.run_until_stalled();

win.egui_platform.handle_event(&event);
Expand All @@ -214,6 +221,7 @@ impl Harness {
present_mode: win.present_mode,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: Vec::new(),
desired_maximum_frame_latency: 1,
};
win.surface.configure(&gfx.device, &config);
win.depth_target = gfx
Expand Down Expand Up @@ -241,11 +249,14 @@ impl Harness {
needs_reload = false;
}
event::WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
target_window.exit();
}
event::WindowEvent::ModifiersChanged(mods) => {
modifiers = mods;
}
event::WindowEvent::KeyboardInput { input, .. } => {
if !app.on_key(input) {
*control_flow = ControlFlow::Exit;
event::WindowEvent::KeyboardInput { event, .. } => {
if !app.on_key(event, modifiers) {
target_window.exit();
}
}
event::WindowEvent::MouseWheel { delta, .. } => app.on_mouse_wheel(delta),
Expand All @@ -257,7 +268,7 @@ impl Harness {
}
_ => {}
},
event::Event::MainEventsCleared => {
event::Event::AboutToWait => {
let duration = time::Instant::now() - last_time;
last_time += duration;

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

let egui_primitives =
win.egui_platform.context().tessellate(egui_output.shapes);
let egui_primitives = win
.egui_platform
.context()
.tessellate(egui_output.shapes, 1.0);
let screen_descriptor = egui_wgpu_backend::ScreenDescriptor {
physical_width: gfx.screen_size.width,
physical_height: gfx.screen_size.height,
Expand Down
63 changes: 36 additions & 27 deletions bin/level/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,69 +191,78 @@ impl Application for LevelView {
}
}

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

let i = &mut self.input;
let alt = modifiers.lalt_state() == ModifiersKeyState::Pressed;
let shift = modifiers.lshift_state() == ModifiersKeyState::Pressed;
#[allow(deprecated)]
match input {
KeyboardInput {
event::KeyEvent {
state: ElementState::Pressed,
virtual_keycode: Some(key),
ref modifiers,
physical_key: PhysicalKey::Code(key),
..
} => match key {
Key::Escape => return false,
Key::W => {
KeyCode::Escape => return false,
KeyCode::KeyW => {
*i = Input::Ver {
dir: self.cam.scale.y,
alt: modifiers.alt(),
shift: modifiers.shift(),
alt,
shift,
}
}
Key::S => {
KeyCode::KeyS => {
*i = Input::Ver {
dir: -self.cam.scale.y,
alt: modifiers.alt(),
shift: modifiers.shift(),
alt,
shift,
}
}
Key::A => {
KeyCode::KeyA => {
*i = Input::Hor {
dir: -self.cam.scale.x,
alt: modifiers.alt(),
shift: modifiers.shift(),
alt,
shift,
}
}
Key::D => {
KeyCode::KeyD => {
*i = Input::Hor {
dir: self.cam.scale.x,
alt: modifiers.alt(),
shift: modifiers.shift(),
alt,
shift,
}
}
Key::Z => {
KeyCode::KeyZ => {
*i = Input::Dep {
dir: -self.cam.scale.z,
alt: modifiers.alt(),
alt,
}
}
Key::X => {
KeyCode::KeyX => {
*i = Input::Dep {
dir: self.cam.scale.z,
alt: modifiers.alt(),
alt,
}
}
Key::LAlt => self.alt_button_pressed = true,
KeyCode::AltLeft => self.alt_button_pressed = true,
_ => (),
},
KeyboardInput {
event::KeyEvent {
state: ElementState::Released,
virtual_keycode: Some(key),
physical_key: PhysicalKey::Code(key),
..
} => match key {
Key::W | Key::S | Key::A | Key::D | Key::Z | Key::X => *i = Input::Empty,
Key::LAlt => self.alt_button_pressed = false,
KeyCode::KeyW
| KeyCode::KeyS
| KeyCode::KeyA
| KeyCode::KeyD
| KeyCode::KeyZ
| KeyCode::KeyX => *i = Input::Empty,
KeyCode::AltLeft => self.alt_button_pressed = false,
_ => (),
},
/*
Expand Down
6 changes: 2 additions & 4 deletions bin/level/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ mod boilerplate;
fn main() {
use std::env;

let (harness, settings) = boilerplate::Harness::init(boilerplate::HarnessOptions {
title: "level",
uses_level: true,
});
let (harness, settings) =
boilerplate::Harness::init(boilerplate::HarnessOptions { title: "level" });

let args: Vec<_> = env::args().collect();
let mut options = getopts::Options::new();
Expand Down
Loading

0 comments on commit 9cebd7f

Please sign in to comment.