Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-core/src/rendering/gpu_info.rs
1//! Module containing types to report GPU information that can be useful debug purposes.
2 
3use std::fmt::{Display, Formatter};
4 
5/// Function called when a GPU device is first selected upon constructing a window.
6pub type OnGPUDeviceSelected = dyn Fn(GPUDeviceInfo) + 'static + Send + Sync;
7 
8/// Physical GPU device types.
9/// This is a direct fork of wgpu's `DeviceType` struct. However, we redefine it to avoid a direct
10/// dependency on wgpu in cases where we don't rely on the wgpu rendering backend.
11///
12/// See <https://docs.rs/wgpu/latest/wgpu/enum.DeviceType.html> for more details.
13#[derive(Debug, Copy, Clone)]
14pub enum GPUDeviceType {
15 /// Other or Unknown.
16 Other,
17 /// Integrated GPU with shared CPU/GPU memory.
18 IntegratedGpu,
19 /// Discrete GPU with separate CPU/GPU memory.
20 DiscreteGpu,
21 /// Virtual / Hosted.
22 VirtualGpu,
23 /// Cpu / Software Rendering.
24 Cpu,
25}
26 
27/// The GPU backend that is being renderer to.
28/// This is a direct fork of wgpu's `Backend` struct. However, we redefine it to avoid a direct
29/// dependency on wgpu in cases where we don't rely on the wgpu rendering backend.
30///
31/// See <https://docs.rs/wgpu/latest/wgpu/enum.Backend.html> for more details.
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
33pub enum GPUBackend {
34 /// Dummy backend, used for testing.
35 Empty,
36 /// Vulkan API
37 Vulkan,
38 /// Metal API (Apple platforms)
39 Metal,
40 /// Direct3D-12 (Windows)
41 Dx12,
42 /// OpenGL ES-3 (Linux, Android)
43 Gl,
44 /// WebGPU in the browser
45 BrowserWebGpu,
46}
47 
48impl Display for GPUBackend {
49 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
50 match self {
51 GPUBackend::Empty => write!(f, "Empty"),
52 GPUBackend::Vulkan => write!(f, "Vulkan"),
53 GPUBackend::Metal => write!(f, "Metal"),
54 GPUBackend::Dx12 => write!(f, "Dx12"),
55 GPUBackend::Gl => write!(f, "Gl"),
56 GPUBackend::BrowserWebGpu => write!(f, "BrowserWebGpu"),
57 }
58 }
59}
60 
61/// Information about the GPU device a given window is rendering to.
62#[derive(Debug)]
63pub struct GPUDeviceInfo {
64 /// The type of the device we are rendering to (e.g. integrated vs discrete).
65 pub device_type: GPUDeviceType,
66 /// The name of the GPU _device_ we are rendering to.
67 pub device_name: String,
68 /// The name of the GPU _driver_ that the OS is using to connect to the given GPU device.
69 pub driver_name: String,
70 /// Any additional information about the driver that the OS is using to connect to the given
71 /// GPU device.
72 pub driver_info: String,
73 /// The backend (e.g. Metal vs Vulkan vs OpenGL) we using when rendering.
74 pub backend: GPUBackend,
75}
76 
77impl Display for GPUDeviceType {
78 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
79 match self {
80 GPUDeviceType::Other => write!(f, "Other"),
81 GPUDeviceType::IntegratedGpu => write!(f, "Integrated"),
82 GPUDeviceType::DiscreteGpu => write!(f, "Discrete"),
83 GPUDeviceType::VirtualGpu => write!(f, "Virtual"),
84 GPUDeviceType::Cpu => write!(f, "Cpu"),
85 }
86 }
87}
88