Improved input lag

* switched to sync_channel in WinitWindow
+ added framerate math (commented)
* improved gpu selection algorithm
This commit is contained in:
Steins7 2021-02-03 11:52:22 +01:00
parent 454cb09bb2
commit 35eed08d5f
4 changed files with 37 additions and 8 deletions

View File

@ -25,7 +25,7 @@ fn setup_logger() -> Result<(), fern::InitError> {
message message
)) ))
}) })
.level(log::LevelFilter::Trace) .level(log::LevelFilter::Debug)
.chain(std::io::stdout()) .chain(std::io::stdout())
.chain(fern::log_file("output.log")?) .chain(fern::log_file("output.log")?)
.apply()?; .apply()?;

View File

@ -45,7 +45,7 @@ where
} }
pub fn run(&mut self) { pub fn run(&mut self) {
use std::time::Duration; use std::time::Duration; //, SystemTime};
use crate::{ use crate::{
subengine::subengine_controller::SubengineCommand, subengine::subengine_controller::SubengineCommand,
@ -56,6 +56,8 @@ where
let mut input_keys: Vec<Key> = Vec::new(); let mut input_keys: Vec<Key> = Vec::new();
loop { loop {
// let frame_start = SystemTime::now();
for pipeline in &mut self.pipelines { for pipeline in &mut self.pipelines {
for input in &pipeline.inputs { for input in &pipeline.inputs {
match input.borrow().read(Duration::from_millis(1)) { match input.borrow().read(Duration::from_millis(1)) {
@ -114,6 +116,20 @@ where
}; };
}; };
}; };
// let frame_time = SystemTime::now()
// .duration_since(frame_start)
// .unwrap();
//
// let sleep_time = Duration::from_secs_f32(1.0/60.0)
// .checked_sub(frame_time)
// .unwrap_or_else(|| {
// info!("Engine overloaded !");
// Duration::from_secs(0)
// });
// std::thread::sleep(sleep_time);
//
// info!("FPS : {}", 1.0/frame_time.as_secs_f32());// + sleep_time.as_secs_f32()));
} }
} }
} }

View File

@ -61,7 +61,7 @@ impl WinitWindow {
//Since we can't move the EventLoop from one thread to another, we need to create it in the //Since we can't move the EventLoop from one thread to another, we need to create it in the
//right thread and then move the Window back to the main thread instead //right thread and then move the Window back to the main thread instead
let cloned_name = name.clone(); let cloned_name = name.clone();
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::sync_channel(1);
let (tmp_tx, tmp_rx) = mpsc::sync_channel(1); let (tmp_tx, tmp_rx) = mpsc::sync_channel(1);
let builder = thread::Builder::new().name(title.into()); let builder = thread::Builder::new().name(title.into());
//the EventLoop hijacks the thread so there is no need to join it later... //the EventLoop hijacks the thread so there is no need to join it later...
@ -92,23 +92,25 @@ impl WinitWindow {
match event { match event {
Event::LoopDestroyed => { Event::LoopDestroyed => {
let _ = tx.send(Key::Closed).unwrap(); tx.send(Key::Closed).unwrap();
debug!("Closed EventLoop"); debug!("Closed EventLoop");
return; return;
}, },
Event::WindowEvent{window_id: _, event} => match event { Event::WindowEvent{window_id: _, event} => match event {
event::WindowEvent::CloseRequested => { event::WindowEvent::CloseRequested => {
debug!("Close requested"); debug!("Close requested");
let _ = tx.send(Key::Close).unwrap(); tx.send(Key::Close).unwrap();
}, },
event::WindowEvent::CursorMoved{position, ..} => { event::WindowEvent::CursorMoved{position, ..} => {
tx.send(Key::MouseMove{ let _ = tx.try_send(Key::MouseMove{
x: position.x, x: position.x,
y: position.y, y: position.y,
}).unwrap(); });
}, },
_ => (), _ => (),
}, },
Event::UserEvent(signal) => match signal { Event::UserEvent(signal) => match signal {
Signal::Exit => { Signal::Exit => {
debug!("Stopping input thread..."); debug!("Stopping input thread...");
@ -118,6 +120,7 @@ impl WinitWindow {
tx.send(Key::Test).unwrap(); tx.send(Key::Test).unwrap();
}, },
}, },
_ => (), _ => (),
}}) }})
}); });

View File

@ -88,6 +88,7 @@ where
use gfx_hal::{ use gfx_hal::{
Instance, Instance,
window::Surface, window::Surface,
adapter::DeviceType,
}; };
// dry run to print all adapters for debug purposes // dry run to print all adapters for debug purposes
@ -103,7 +104,7 @@ where
let adapter = instance let adapter = instance
.enumerate_adapters() .enumerate_adapters()
.into_iter() .into_iter()
.find(|a| { .filter(|a| {
a.queue_families a.queue_families
.iter() .iter()
.any(|qf| .any(|qf|
@ -113,7 +114,16 @@ where
.all(|surface| .all(|surface|
surface.supports_queue_family(&qf) surface.supports_queue_family(&qf)
))}) ))})
.max_by_key(|adapter| {
match adapter.info.device_type {
DeviceType::DiscreteGpu => 4,
DeviceType::IntegratedGpu => 3,
DeviceType::VirtualGpu => 2,
DeviceType::Other => 1,
DeviceType::Cpu => 0,
}})
.ok_or("Could not find a graphical adapter")?; .ok_or("Could not find a graphical adapter")?;
info!("Selected adapter : {}", adapter.info.name); info!("Selected adapter : {}", adapter.info.name);
adapter adapter