diff options
-rw-r--r-- | Cargo.lock | 76 | ||||
-rw-r--r-- | client/Cargo.toml | 5 | ||||
-rw-r--r-- | client/src/main.rs | 20 | ||||
-rw-r--r-- | client/src/render/scene/textures.rs | 84 |
4 files changed, 149 insertions, 36 deletions
@@ -19,6 +19,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" [[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] name = "adler2" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -275,6 +284,21 @@ dependencies = [ ] [[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] + +[[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1055,6 +1079,12 @@ dependencies = [ ] [[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] name = "flate2" version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1144,6 +1174,12 @@ dependencies = [ ] [[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] name = "gl_generator" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2101,6 +2137,15 @@ dependencies = [ ] [[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] name = "oboe" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2169,10 +2214,13 @@ version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ + "backtrace", "cfg-if", "libc", + "petgraph", "redox_syscall 0.5.8", "smallvec", + "thread-id", "windows-targets 0.52.6", ] @@ -2189,6 +2237,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap 2.7.0", +] + +[[package]] name = "pin-project" version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2560,6 +2618,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" [[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2858,6 +2922,16 @@ dependencies = [ ] [[package]] +name = "thread-id" +version = "4.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe8f25bbdd100db7e1d34acf7fd2dc59c4bf8f7483f505eaa7d4f12f76cc0ea" +dependencies = [ + "libc", + "winapi", +] + +[[package]] name = "tiff" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3245,8 +3319,10 @@ dependencies = [ "image", "log", "nnnoiseless", + "parking_lot", "pollster", "rand 0.9.0-beta.1", + "rayon", "weareshared", "wgpu", "winit", diff --git a/client/Cargo.toml b/client/Cargo.toml index 762e711..4a22bf6 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -23,3 +23,8 @@ bytemuck = "1.21.0" xdg = "2.5.2" nnnoiseless = "0.5.1" humansize = "2.1.3" +rayon = "1.10.0" +parking_lot = "0.12.3" + +[features] +deadlock_detection = ["parking_lot/deadlock_detection"] diff --git a/client/src/main.rs b/client/src/main.rs index e5141c7..804ab44 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -46,6 +46,9 @@ fn main() -> Result<()> { env_logger::init_from_env("LOG"); let args = Args::parse(); + #[cfg(feature = "deadlock_detection")] + std::thread::spawn(deadlock_task); + info!("connecting..."); let mut sock = TcpStream::connect(args.address)?; Packet::Connect(random()).write(&mut sock)?; @@ -56,3 +59,20 @@ fn main() -> Result<()> { Ok(()) } + +#[cfg(feature = "deadlock_detection")] +fn deadlock_task() { + let deadlocks = loop { + std::thread::sleep(std::time::Duration::from_secs(1)); + let deadlocks = parking_lot::deadlock::check_deadlock(); + if !deadlocks.is_empty() { + break deadlocks; + } + }; + for threads in &deadlocks { + for t in threads { + println!("thread {:#?}", t.thread_id()); + println!("{:#?}", t.backtrace()); + } + } +} diff --git a/client/src/render/scene/textures.rs b/client/src/render/scene/textures.rs index c385be2..2da84be 100644 --- a/client/src/render/scene/textures.rs +++ b/client/src/render/scene/textures.rs @@ -18,7 +18,12 @@ use super::{GraphicsConfig, ScenePreparer, TextureIdentityKind}; use anyhow::Result; use image::ImageReader; use log::debug; -use std::{io::Cursor, sync::Arc, time::Instant}; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; +use std::{ + io::Cursor, + sync::{Arc, atomic::AtomicUsize}, + time::Instant, +}; use wgpu::{ AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindingResource, Color, ColorTargetState, ColorWrites, CommandEncoderDescriptor, Device, Extent3d, FilterMode, @@ -99,42 +104,49 @@ impl ScenePreparer { self.placeholder_textures.insert(kind, tex_bg, 4); *num_done += 1; } - for spec in self.textures.needed() { - let start = Instant::now(); - let format = if spec.linear { - TextureFormat::Rgba8Unorm - } else { - TextureFormat::Rgba8UnormSrgb - }; - if let Some(mipgen) = self.mip_generation_pipelines.try_get(format) { - if let Some(buf) = self.downloader.try_get(spec.data.clone())? { - let image = ImageReader::new(Cursor::new(buf.0)).with_guessed_format()?; - let image = image.decode()?; - let dims = (image.width(), image.height()); - let image = image.into_rgba8(); - let image = image.into_vec(); - let tex_bg = create_texture( - &self.device, - &self.queue, - &self.layouts.texture, - &image, - dims.0, - dims.1, - format, - Some(&mipgen), - &self.config.read().unwrap().clone(), - ); - self.textures.insert(spec, tex_bg, image.len()); - debug!( - "texture created (res={}x{}, took {:?})", - dims.0, - dims.1, - start.elapsed() - ); - *num_done += 1; + + let numdone = AtomicUsize::new(0); + self.textures + .needed() + .into_par_iter() + .try_for_each(|spec| { + let start = Instant::now(); + let format = if spec.linear { + TextureFormat::Rgba8Unorm + } else { + TextureFormat::Rgba8UnormSrgb + }; + if let Some(mipgen) = self.mip_generation_pipelines.try_get(format) { + if let Some(buf) = self.downloader.try_get(spec.data.clone())? { + let image = ImageReader::new(Cursor::new(buf.0)).with_guessed_format()?; + let image = image.decode()?; + let dims = (image.width(), image.height()); + let image = image.into_rgba8(); + let image = image.into_vec(); + let tex_bg = create_texture( + &self.device, + &self.queue, + &self.layouts.texture, + &image, + dims.0, + dims.1, + format, + Some(&mipgen), + &self.config.read().unwrap().clone(), + ); + self.textures.insert(spec, tex_bg, image.len()); + debug!( + "texture created (res={}x{}, took {:?})", + dims.0, + dims.1, + start.elapsed() + ); + numdone.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } } - } - } + Ok::<(), anyhow::Error>(()) + })?; + *num_done += numdone.load(std::sync::atomic::Ordering::Relaxed); Ok(()) } } |