forked from nonsensical-dev/zenyx-engine
add window icon
This commit is contained in:
parent
7d4f7cbc1d
commit
9088d0aa49
12 changed files with 165 additions and 117 deletions
|
@ -1,9 +1,10 @@
|
|||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use sysinfo::{CpuRefreshKind, RefreshKind, System};
|
||||
|
||||
use raw_cpuid::CpuId;
|
||||
use sysinfo::{CpuRefreshKind, RefreshKind, System};
|
||||
use wgpu::DeviceType;
|
||||
use std::collections::HashSet;
|
||||
|
||||
mod build_info {
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
|
@ -24,11 +25,15 @@ impl Memory {
|
|||
}
|
||||
|
||||
pub const fn from_mb(mb: u64) -> Self {
|
||||
Self { bytes: mb * 1024 * 1024 }
|
||||
Self {
|
||||
bytes: mb * 1024 * 1024,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn from_gb(gb: u64) -> Self {
|
||||
Self { bytes: gb * 1024 * 1024 * 1024 }
|
||||
Self {
|
||||
bytes: gb * 1024 * 1024 * 1024,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn as_bytes(&self) -> u64 {
|
||||
|
@ -185,18 +190,24 @@ pub struct CPU {
|
|||
|
||||
impl CPU {
|
||||
pub fn current() -> Self {
|
||||
let mut sys = System::new_with_specifics(RefreshKind::default().with_cpu(CpuRefreshKind::everything()));
|
||||
let mut sys = System::new_with_specifics(
|
||||
RefreshKind::default().with_cpu(CpuRefreshKind::everything()),
|
||||
);
|
||||
sys.refresh_cpu_all();
|
||||
|
||||
let cpu_opt = sys.cpus().first();
|
||||
|
||||
let brand = cpu_opt.map(|cpu| cpu.brand().into())
|
||||
let brand = cpu_opt
|
||||
.map(|cpu| cpu.brand().into())
|
||||
.unwrap_or(CPUBrand::Other("unknown".into()));
|
||||
let name = cpu_opt.map(|cpu| cpu.name().to_string())
|
||||
let name = cpu_opt
|
||||
.map(|cpu| cpu.name().to_string())
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
let vendor_id = cpu_opt.map(|cpu| cpu.vendor_id().to_string())
|
||||
let vendor_id = cpu_opt
|
||||
.map(|cpu| cpu.vendor_id().to_string())
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
let max_clock_speed = cpu_opt.map(|cpu| ClockSpeed(cpu.frequency() as u32))
|
||||
let max_clock_speed = cpu_opt
|
||||
.map(|cpu| ClockSpeed(cpu.frequency() as u32))
|
||||
.unwrap_or(ClockSpeed(0));
|
||||
let current_clock_speed = max_clock_speed;
|
||||
|
||||
|
@ -214,20 +225,26 @@ impl CPU {
|
|||
let size = cache.physical_line_partitions()
|
||||
* cache.coherency_line_size()
|
||||
* cache.associativity();
|
||||
if size > 0 { l1_cache = Some(Memory::from_bytes(size.try_into().unwrap())); }
|
||||
},
|
||||
if size > 0 {
|
||||
l1_cache = Some(Memory::from_bytes(size.try_into().unwrap()));
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
let size = cache.physical_line_partitions()
|
||||
* cache.coherency_line_size()
|
||||
* cache.associativity();
|
||||
if size > 0 { l2_cache = Some(Memory::from_bytes(size.try_into().unwrap())); }
|
||||
},
|
||||
if size > 0 {
|
||||
l2_cache = Some(Memory::from_bytes(size.try_into().unwrap()));
|
||||
}
|
||||
}
|
||||
3 => {
|
||||
let size = (cache.physical_line_partitions() as u64)
|
||||
* (cache.coherency_line_size() as u64)
|
||||
* (cache.associativity() as u64);
|
||||
if size > 0 { l3_cache = Some(Memory::from_bytes(size)); }
|
||||
},
|
||||
if size > 0 {
|
||||
l3_cache = Some(Memory::from_bytes(size));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +252,9 @@ impl CPU {
|
|||
|
||||
Self {
|
||||
brand,
|
||||
arch: std::env::consts::ARCH.parse().unwrap_or(CPUArch::Other("unknown".into())),
|
||||
arch: std::env::consts::ARCH
|
||||
.parse()
|
||||
.unwrap_or(CPUArch::Other("unknown".into())),
|
||||
name,
|
||||
vendor_id,
|
||||
physical_cores,
|
||||
|
@ -257,7 +276,7 @@ impl CPU {
|
|||
}
|
||||
|
||||
pub fn is_arm(&self) -> bool {
|
||||
matches!(self.brand,CPUBrand::Intel)
|
||||
matches!(self.brand, CPUBrand::Intel)
|
||||
}
|
||||
|
||||
pub fn is_high_clock(&self) -> bool {
|
||||
|
@ -278,13 +297,23 @@ impl CPU {
|
|||
self.arch,
|
||||
self.name,
|
||||
self.vendor_id,
|
||||
self.physical_cores.map(|c| c.to_string()).unwrap_or_else(|| "unknown".into()),
|
||||
self.logical_cores.map(|c| c.to_string()).unwrap_or_else(|| "unknown".into()),
|
||||
self.physical_cores
|
||||
.map(|c| c.to_string())
|
||||
.unwrap_or_else(|| "unknown".into()),
|
||||
self.logical_cores
|
||||
.map(|c| c.to_string())
|
||||
.unwrap_or_else(|| "unknown".into()),
|
||||
self.max_clock_speed,
|
||||
self.current_clock_speed,
|
||||
self.l1_cache.map(|c| c.format_human()).unwrap_or_else(|| "unknown".into()),
|
||||
self.l2_cache.map(|c| c.format_human()).unwrap_or_else(|| "unknown".into()),
|
||||
self.l3_cache.map(|c| c.format_human()).unwrap_or_else(|| "unknown".into()),
|
||||
self.l1_cache
|
||||
.map(|c| c.format_human())
|
||||
.unwrap_or_else(|| "unknown".into()),
|
||||
self.l2_cache
|
||||
.map(|c| c.format_human())
|
||||
.unwrap_or_else(|| "unknown".into()),
|
||||
self.l3_cache
|
||||
.map(|c| c.format_human())
|
||||
.unwrap_or_else(|| "unknown".into()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +361,6 @@ pub struct GPU {
|
|||
pub driver_version: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
impl GPU {
|
||||
pub fn current() -> Vec<Self> {
|
||||
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
|
||||
|
@ -363,6 +391,7 @@ impl GPU {
|
|||
pub fn is_dedicated(&self) -> bool {
|
||||
!self.is_integrated()
|
||||
}
|
||||
|
||||
pub fn is_mobile(&self) -> bool {
|
||||
let lower_name = self.name.to_lowercase();
|
||||
lower_name.contains("adreno")
|
||||
|
@ -490,6 +519,7 @@ impl SystemMetadata {
|
|||
compile_info: CompileInfo::current(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_gpu(&self) -> Option<&GPU> {
|
||||
self.gpus
|
||||
.iter()
|
||||
|
@ -498,7 +528,6 @@ impl SystemMetadata {
|
|||
.or_else(|| self.gpus.first())
|
||||
}
|
||||
|
||||
|
||||
pub fn verbose_summary(&self) -> String {
|
||||
let main_gpu = self.main_gpu();
|
||||
let main_gpu_info = main_gpu
|
||||
|
@ -556,4 +585,4 @@ mod tests {
|
|||
assert!(metadata.memory.total.as_bytes() > 0);
|
||||
assert!(!metadata.compile_info.pkg_version.is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue