Merge branch 'imbris/small-fixes' into 'master'

Small fixes

See merge request veloren/veloren!2461
This commit is contained in:
Imbris 2021-06-16 08:18:45 +00:00
commit a9229e3625
4 changed files with 98 additions and 33 deletions

View File

@ -43,7 +43,11 @@ impl<'a> System<'a> for Sys {
{
// Update interpolation values, but don't interpolate far things or objects
if i.pos.distance_squared(pos.0) < 64.0 * 64.0 && !matches!(body, Body::Object(_)) {
i.pos = Lerp::lerp(i.pos, pos.0 + vel.0 * 0.03, 10.0 * dt.0);
// Note, these values are specifically tuned for smoother motion with high
// network latency or low network sampling rate and for smooth
// block hopping (which is instantaneous)
const POS_LERP_RATE_FACTOR: f32 = 10.0;
i.pos = Lerp::lerp(i.pos, pos.0 + vel.0 * 0.03, POS_LERP_RATE_FACTOR * dt.0);
i.ori = Ori::slerp(i.ori, *ori, base_ori_interp(body) * dt.0);
} else {
i.pos = pos.0;

View File

@ -239,6 +239,7 @@ widget_ids! {
num_lights,
num_figures,
num_particles,
graphics_backend,
gpu_timings[],
// Game Version
@ -2211,6 +2212,17 @@ impl Hud {
.font_size(self.fonts.cyri.scale(14))
.set(self.ids.num_particles, ui_widgets);
// Graphics backend
Text::new(&format!(
"Graphics backend: {}",
global_state.window.renderer().graphics_backend(),
))
.color(TEXT_COLOR)
.down_from(self.ids.num_particles, 5.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(14))
.set(self.ids.graphics_backend, ui_widgets);
// GPU timing for different pipelines
let gpu_timings = global_state.window.renderer().timings();
if !gpu_timings.is_empty() {

View File

@ -139,6 +139,9 @@ pub struct Renderer {
// This checks is added because windows resizes the window to 0,0 when
// minimizing and this causes a bunch of validation errors
is_minimized: bool,
// To remember the backend info after initialization for debug purposes
graphics_backend: String,
}
impl Renderer {
@ -188,37 +191,73 @@ impl Renderer {
))
.ok_or(RenderError::CouldNotFindAdapter)?;
let info = adapter.get_info();
info!(
?info.name,
?info.vendor,
?info.backend,
?info.device,
?info.device_type,
"selected graphics device"
);
let graphics_backend = format!("{:?}", &info.backend);
let limits = wgpu::Limits {
max_push_constant_size: 64,
..Default::default()
};
let (device, queue) = futures_executor::block_on(
adapter.request_device(
&wgpu::DeviceDescriptor {
// TODO
label: None,
features: wgpu::Features::DEPTH_CLAMPING
| wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER
| wgpu::Features::PUSH_CONSTANTS
| (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES),
limits,
},
std::env::var_os("WGPU_TRACE_DIR")
.as_ref()
.map(|v| std::path::Path::new(v)),
),
)?;
let (device, queue) = futures_executor::block_on(adapter.request_device(
&wgpu::DeviceDescriptor {
// TODO
label: None,
features: wgpu::Features::DEPTH_CLAMPING
| wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER
| wgpu::Features::PUSH_CONSTANTS
| (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES),
limits,
},
std::env::var_os("WGPU_TRACE_DIR").as_ref().map(|v| {
let path = std::path::Path::new(v);
// We don't want to continue if we can't actually collect the api trace
if !path.exists() {
panic!(
"WGPU_TRACE_DIR is set to the path \"{}\" which doesn't exist",
path.display()
);
}
if !path.is_dir() {
panic!(
"WGPU_TRACE_DIR is set to the path \"{}\" which is not a directory",
path.display()
);
}
if path
.read_dir()
.expect("Could not read the directory that is specified by WGPU_TRACE_DIR")
.next()
.is_some()
{
panic!(
"WGPU_TRACE_DIR is set to the path \"{}\" which already contains other \
files",
path.display()
);
}
path
}),
))?;
// Set error handler for wgpu errors
// This is better for use than their default because it includes the error in
// the panic message
device.on_uncaptured_error(|error| {
device.on_uncaptured_error(move |error| {
error!("{}", &error);
panic!(
"wgpu error (handling all wgpu errors as fatal): {:?}",
&error,
)
"wgpu error (handling all wgpu errors as fatal):\n{:?}\n{:?}",
&error, &info,
);
});
let profiler_features_enabled = device
@ -231,19 +270,10 @@ impl Renderer {
);
}
let info = adapter.get_info();
info!(
?info.name,
?info.vendor,
?info.backend,
?info.device,
?info.device_type,
"selected graphics device"
);
let format = adapter
.get_swap_chain_preferred_format(&surface)
.expect("No supported swap chain format found");
info!("Using {:?} as the swapchain format", format);
let sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
@ -401,9 +431,14 @@ impl Renderer {
profiler_features_enabled,
is_minimized: false,
graphics_backend,
})
}
/// Get the graphics backend being used
pub fn graphics_backend(&self) -> &str { &self.graphics_backend }
/// Check the status of the intial pipeline creation
/// Returns `None` if complete
/// Returns `Some((total, complete))` if in progress

View File

@ -5,7 +5,7 @@ use super::{
model::{DynamicModel, Model, SubModel},
pipelines::{
blit, clouds, debug, figure, fluid, lod_terrain, particle, shadow, skybox, sprite,
terrain, ui, ColLights, GlobalsBindGroup,
terrain, ui, ColLights, GlobalsBindGroup, ShadowTexturesBindGroup,
},
},
Renderer, ShadowMap, ShadowMapRenderer,
@ -198,6 +198,7 @@ impl<'frame> Drawer<'frame> {
borrow: &self.borrow,
pipelines,
globals: self.globals,
shadows: &shadow.bind,
})
}
@ -522,6 +523,7 @@ pub struct FirstPassDrawer<'pass> {
borrow: &'pass RendererBorrow<'pass>,
pipelines: &'pass super::Pipelines,
globals: &'pass GlobalsBindGroup,
shadows: &'pass ShadowTexturesBindGroup,
}
impl<'pass> FirstPassDrawer<'pass> {
@ -540,7 +542,10 @@ impl<'pass> FirstPassDrawer<'pass> {
render_pass.set_pipeline(&self.pipelines.debug.pipeline);
set_quad_index_buffer::<debug::Vertex>(&mut render_pass, &self.borrow);
DebugDrawer { render_pass }
DebugDrawer {
render_pass,
shadows: self.shadows,
}
}
pub fn draw_lod_terrain<'data: 'pass>(&mut self, model: &'data Model<lod_terrain::Vertex>) {
@ -613,6 +618,7 @@ impl<'pass> FirstPassDrawer<'pass> {
pub struct DebugDrawer<'pass_ref, 'pass: 'pass_ref> {
render_pass: Scope<'pass_ref, wgpu::RenderPass<'pass>>,
shadows: &'pass ShadowTexturesBindGroup,
}
impl<'pass_ref, 'pass: 'pass_ref> DebugDrawer<'pass_ref, 'pass> {
@ -627,6 +633,14 @@ impl<'pass_ref, 'pass: 'pass_ref> DebugDrawer<'pass_ref, 'pass> {
}
}
impl<'pass_ref, 'pass: 'pass_ref> Drop for DebugDrawer<'pass_ref, 'pass> {
fn drop(&mut self) {
// Maintain that the shadow bind group is set in
// slot 1 by default during the main pass
self.render_pass
.set_bind_group(1, &self.shadows.bind_group, &[]);
}
}
pub struct FigureDrawer<'pass_ref, 'pass: 'pass_ref> {
render_pass: Scope<'pass_ref, wgpu::RenderPass<'pass>>,
}