1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::collections::HashMap;

use serde::Deserialize;
use wgpu::{
    AdapterInfo, DownlevelCapabilities, Features, Limits, TextureFormat, TextureFormatFeatures,
};

/// Report specifying the capabilities of the GPUs on the system.
///
/// Must be synchronized with the definition on wgpu-info/src/report.rs.
#[derive(Deserialize)]
pub(crate) struct GpuReport {
    #[cfg_attr(target_arch = "wasm32", allow(unused))]
    pub devices: Vec<AdapterReport>,
}

impl GpuReport {
    #[cfg_attr(target_arch = "wasm32", allow(unused))]
    pub(crate) fn from_json(file: &str) -> serde_json::Result<Self> {
        profiling::scope!("Parsing .gpuconfig");
        serde_json::from_str(file)
    }
}

/// A single report of the capabilities of an Adapter.
///
/// Must be synchronized with the definition on wgpu-info/src/report.rs.
#[derive(Deserialize, Clone)]
pub struct AdapterReport {
    pub info: AdapterInfo,
    pub features: Features,
    pub limits: Limits,
    pub downlevel_caps: DownlevelCapabilities,
    #[allow(unused)]
    pub texture_format_features: HashMap<TextureFormat, TextureFormatFeatures>,
}

impl AdapterReport {
    pub(crate) fn from_adapter(adapter: &wgpu::Adapter) -> Self {
        let info = adapter.get_info();
        let features = adapter.features();
        let limits = adapter.limits();
        let downlevel_caps = adapter.get_downlevel_capabilities();

        Self {
            info,
            features,
            limits,
            downlevel_caps,
            texture_format_features: HashMap::new(), // todo
        }
    }
}