Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = ["client", "server", "common"]

[profile.dev]
opt-level = 1
debug-assertions = true

[profile.dev.package."*"]
opt-level = 2
Expand Down
18 changes: 9 additions & 9 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ server = { path = "../server" }
tracing = "0.1.10"
ash = { version = "0.37.0", features = ["loaded"] }
lahar = { git = "https://github.com/Ralith/lahar", rev = "88abd75e41d04c3a4199d95f581cb135f5962844" }
winit = "0.26.1"
ash-window = "0.10.0"
winit = "0.27.2"
ash-window = "0.12.0"
raw-window-handle = "0.5.0"
directories = "4.0.1"
vk-shader-macros = "0.2.5"
na = { package = "nalgebra", version = "0.19" }
nalgebra = "0.31.2"
tokio = { version = "1.18.2", features = ["rt-multi-thread", "sync", "macros"] }
png = "0.17.5"
anyhow = "1.0.26"
Expand All @@ -30,21 +31,20 @@ downcast-rs = "1.1.1"
quinn = "0.8.3"
futures-util = "0.3.1"
rustls = { version = "0.20.6", features = ["dangerous_configuration"] }
webpki = "0.21.0"
hecs = "0.7.6"
rcgen = { version = "0.9.2", default-features = false }
webpki = "0.22.0"
hecs = "0.9.0"
rcgen = { version = "0.10.0", default-features = false }
memoffset = "0.6"
gltf = { version = "1.0.0", default-features = false, features = ["utils"] }
metrics = { version = "0.12.1", features = ["std"] }
metrics-core = "0.5.2"
metrics = { version = "0.20.1" }
hdrhistogram = { version = "7", default-features = false }

[features]
default = ["use-repo-assets"]
use-repo-assets = []

[dev-dependencies]
approx = "0.3.2"
approx = "0.5.1"
bencher = "0.1.5"
renderdoc = "0.10.1"

Expand Down
18 changes: 10 additions & 8 deletions client/src/graphics/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::Instant;
use ash::vk;
use fxhash::FxHashSet;
use lahar::Staged;
use metrics::timing;
use metrics::histogram;

use super::{fog, voxels, Base, Fog, Frustum, GltfScene, Meshes, Voxels};
use crate::{sim, Asset, Config, Loader, Sim};
Expand Down Expand Up @@ -312,10 +312,12 @@ impl Draw {
vk::QueryResultFlags::TYPE_64 | vk::QueryResultFlags::WAIT,
)
.unwrap();
let draw_nanos = self.gfx.limits.timestamp_period * (queries[1] - queries[0]) as f32;
let after_nanos = self.gfx.limits.timestamp_period * (queries[2] - queries[1]) as f32;
timing!("frame.gpu.draw", draw_nanos as u64);
timing!("frame.gpu.after_draw", after_nanos as u64);
let draw_seconds =
self.gfx.limits.timestamp_period as f64 * 1e-9 * (queries[1] - queries[0]) as f64;
let after_seconds =
self.gfx.limits.timestamp_period as f64 * 1e-9 * (queries[2] - queries[1]) as f64;
histogram!("frame.gpu.draw", draw_seconds);
histogram!("frame.gpu.after_draw", after_seconds);
}

device
Expand Down Expand Up @@ -447,10 +449,10 @@ impl Draw {
}
let pos = sim
.world
.get::<Position>(entity)
.get::<&Position>(entity)
.expect("positionless entity in graph");
if let Some(character_model) = self.loader.get(self.character_model) {
if let Ok(ch) = sim.world.get::<Character>(entity) {
if let Ok(ch) = sim.world.get::<&Character>(entity) {
let transform = transform
* pos.local
* na::Matrix4::new_scaling(params.meters_to_absolute)
Expand Down Expand Up @@ -516,7 +518,7 @@ impl Draw {
.unwrap();
state.used = true;
state.in_flight = true;
timing!("frame.cpu", draw_started.elapsed());
histogram!("frame.cpu", draw_started.elapsed());
}

/// Wait for all drawing to complete
Expand Down
8 changes: 4 additions & 4 deletions client/src/graphics/voxels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod tests;
use std::{sync::Arc, time::Instant};

use ash::{vk, Device};
use metrics::timing;
use metrics::histogram;
use tracing::warn;

use super::draw::nearby_nodes;
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Voxels {
&view,
f64::from(self.config.local_simulation.view_distance),
);
timing!(
histogram!(
"frame.cpu.voxels.graph_traversal",
graph_traversal_started.elapsed()
);
Expand Down Expand Up @@ -240,7 +240,7 @@ impl Voxels {
cmd,
&extractions,
);
timing!("frame.cpu.voxels.node_scan", node_scan_started.elapsed());
histogram!("frame.cpu.voxels.node_scan", node_scan_started.elapsed());
}

pub unsafe fn draw(
Expand All @@ -265,7 +265,7 @@ impl Voxels {
for chunk in &frame.drawn {
self.draw.draw(device, cmd, &self.surfaces, chunk.0);
}
timing!("frame.cpu.voxels.draw", started.elapsed());
histogram!("frame.cpu.voxels.draw", started.elapsed());
}

pub unsafe fn destroy(&mut self, device: &Device) {
Expand Down
26 changes: 19 additions & 7 deletions client/src/graphics/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use std::{f32, os::raw::c_char};

use ash::{extensions::khr, vk};
use lahar::DedicatedImage;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use tracing::info;
use winit::{
dpi::PhysicalSize,
event::{
DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent,
},
event_loop::{ControlFlow, EventLoop},
window::{Window as WinitWindow, WindowBuilder},
window::{CursorGrabMode, Window as WinitWindow, WindowBuilder},
};

use super::{Base, Core, Draw, Frustum};
Expand All @@ -35,7 +36,8 @@ impl EarlyWindow {

/// Identify the Vulkan extension needed to render to this window
pub fn required_extensions(&self) -> &'static [*const c_char] {
ash_window::enumerate_required_extensions(&self.window).expect("unsupported platform")
ash_window::enumerate_required_extensions(self.event_loop.raw_display_handle())
.expect("unsupported platform")
}
}

Expand Down Expand Up @@ -64,7 +66,14 @@ impl Window {
sim: Sim,
) -> Self {
let surface = unsafe {
ash_window::create_surface(&core.entry, &core.instance, &early.window, None).unwrap()
ash_window::create_surface(
&core.entry,
&core.instance,
early.window.raw_display_handle(),
early.window.raw_window_handle(),
None,
)
.unwrap()
};
let surface_fn = khr::Surface::new(&core.entry, &core.instance);

Expand Down Expand Up @@ -180,7 +189,10 @@ impl Window {
state: ElementState::Pressed,
..
} => {
let _ = self.window.set_cursor_grab(true);
let _ = self
.window
.set_cursor_grab(CursorGrabMode::Confined)
.or_else(|_e| self.window.set_cursor_grab(CursorGrabMode::Locked));
self.window.set_cursor_visible(false);
mouse_captured = true;
}
Expand Down Expand Up @@ -218,15 +230,15 @@ impl Window {
down = state == ElementState::Pressed;
}
VirtualKeyCode::Escape => {
let _ = self.window.set_cursor_grab(false);
let _ = self.window.set_cursor_grab(CursorGrabMode::None);
self.window.set_cursor_visible(true);
mouse_captured = false;
}
_ => {}
},
WindowEvent::Focused(focused) => {
if !focused {
let _ = self.window.set_cursor_grab(false);
let _ = self.window.set_cursor_grab(CursorGrabMode::None);
self.window.set_cursor_visible(true);
mouse_captured = false;
}
Expand Down Expand Up @@ -314,7 +326,7 @@ impl SwapchainMgr {
/// Construct a swapchain manager for a certain window
fn new(window: &Window, gfx: Arc<Base>, fallback_size: PhysicalSize<u32>) -> Self {
let device = &*gfx.device;
let swapchain_fn = khr::Swapchain::new(&gfx.core.instance, &*device);
let swapchain_fn = khr::Swapchain::new(&gfx.core.instance, device);
let surface_formats = unsafe {
window
.surface_fn
Expand Down
1 change: 1 addition & 0 deletions client/src/lahar_deprecated/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl fmt::Display for ShutDown {

impl std::error::Error for ShutDown {}

#[allow(clippy::type_complexity)]
struct Message {
sender: oneshot::Sender<()>,
op: Box<dyn FnOnce(&mut TransferContext, vk::CommandBuffer) + Send>,
Expand Down
1 change: 1 addition & 0 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ macro_rules! cstr {
}};
}

extern crate nalgebra as na;
mod config;
pub mod graphics;
mod lahar_deprecated;
Expand Down
66 changes: 54 additions & 12 deletions client/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};

use hdrhistogram::Histogram;
use metrics_core::Key;
use tracing::info;

pub fn init() -> Arc<Recorder> {
Expand All @@ -17,11 +16,13 @@ pub fn init() -> Arc<Recorder> {
}

pub struct Recorder {
histograms: RwLock<HashMap<Key, Mutex<Histogram<u64>>>>,
histograms: RwLock<HashMap<metrics::Key, Mutex<Histogram<u64>>>>,
}

impl Recorder {
pub fn report(&self) {
// metrics crate documentation assures us that Key's interior mutability does not affect the hash code.
#[allow(clippy::mutable_key_type)]
let histograms = &*self.histograms.read().unwrap();
for (key, histogram) in histograms {
let histogram = histogram.lock().unwrap();
Expand All @@ -40,29 +41,70 @@ impl Recorder {
struct ArcRecorder(Arc<Recorder>);

impl metrics::Recorder for ArcRecorder {
fn increment_counter(&self, _key: Key, _value: u64) {
fn describe_counter(
&self,
_key: metrics::KeyName,
_unit: Option<metrics::Unit>,
_description: metrics::SharedString,
) {
todo!()
}

fn update_gauge(&self, _key: Key, _value: i64) {
fn describe_gauge(
&self,
_key: metrics::KeyName,
_unit: Option<metrics::Unit>,
_description: metrics::SharedString,
) {
todo!()
}

fn record_histogram(&self, key: Key, value: u64) {
let mut histograms = self.0.histograms.read().unwrap();
let mut histogram = match histograms.get(&key) {
fn describe_histogram(
&self,
_key: metrics::KeyName,
_unit: Option<metrics::Unit>,
_description: metrics::SharedString,
) {
todo!()
}

fn register_counter(&self, _key: &metrics::Key) -> metrics::Counter {
todo!()
}

fn register_gauge(&self, _key: &metrics::Key) -> metrics::Gauge {
todo!()
}

fn register_histogram(&self, key: &metrics::Key) -> metrics::Histogram {
metrics::Histogram::from_arc(Arc::new(Handle {
recorder: self.0.clone(),
key: key.clone(),
}))
}
}

struct Handle {
recorder: Arc<Recorder>,
key: metrics::Key,
}

impl metrics::HistogramFn for Handle {
fn record(&self, value: f64) {
let mut histograms = self.recorder.histograms.read().unwrap();
let mut histogram = match histograms.get(&self.key) {
Some(x) => x.lock().unwrap(),
None => {
drop(histograms);
self.0
self.recorder
.histograms
.write()
.unwrap()
.insert(key.clone(), Mutex::new(Histogram::new(3).unwrap()));
histograms = self.0.histograms.read().unwrap();
histograms.get(&key).unwrap().lock().unwrap()
.insert(self.key.clone(), Mutex::new(Histogram::new(3).unwrap()));
histograms = self.recorder.histograms.read().unwrap();
histograms.get(&self.key).unwrap().lock().unwrap()
}
};
histogram.record(value).unwrap();
histogram.record((value * 1e9) as u64).unwrap();
}
}
12 changes: 6 additions & 6 deletions client/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Sim {
for &(id, orientation) in &msg.character_orientations {
match self.entity_ids.get(&id) {
None => debug!(%id, "character orientation update for unknown entity"),
Some(&entity) => match self.world.get_mut::<Character>(entity) {
Some(&entity) => match self.world.get::<&mut Character>(entity) {
Ok(mut ch) => {
ch.orientation = orientation;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ impl Sim {

match self.entity_ids.get(&id) {
None => debug!(%id, "position update for unknown entity"),
Some(&entity) => match self.world.get_mut::<Position>(entity) {
Some(&entity) => match self.world.get::<&mut Position>(entity) {
Ok(mut pos) => {
if id_is_character {
let p0 = node_transform * pos.local * math::origin();
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Sim {
let params = self.params.as_ref().unwrap();
let local_velocity = self
.world
.get_mut::<Position>(self.local_character.unwrap())
.get::<&mut Position>(self.local_character.unwrap())
.unwrap()
.local
.try_inverse()
Expand Down Expand Up @@ -324,15 +324,15 @@ impl Sim {
fn destroy(&mut self, entity: Entity) {
let id = *self
.world
.get::<EntityId>(entity)
.get::<&EntityId>(entity)
.expect("destroyed nonexistent entity");
self.entity_ids.remove(&id);
self.destroy_idless(entity);
}

/// Destroy an entity without an EntityId mapped
fn destroy_idless(&mut self, entity: Entity) {
if let Ok(position) = self.world.get::<Position>(entity) {
if let Ok(position) = self.world.get::<&Position>(entity) {
self.graph_entities.remove(position.node, entity);
}
self.world
Expand All @@ -352,7 +352,7 @@ impl Sim {

// eventually this should be expanded to work on every entity with a physics property, but for now it is just the player
match self.local_character {
Some(entity) => match self.world.get_mut::<Position>(entity) {
Some(entity) => match self.world.get::<&mut Position>(entity) {
Ok(character_position) => {
// starting with simpler method for testing purposese
let is_colliding = self.check_collision(*character_position);
Expand Down
Loading