easy_wgpu/
gpu.rs

1/// Convenience function for passing around gpu-related data liek device and
2/// queue
3#[derive(Debug)]
4pub struct Gpu {
5    // The order of properties in a struct is the order in which items are dropped.
6    // wgpu seems to require that the device be dropped last, otherwise there is a resouce
7    // leak.
8    adapter: wgpu::Adapter,
9    instance: wgpu::Instance,
10    queue: wgpu::Queue,
11    device: wgpu::Device,
12    limits: wgpu::Limits,
13}
14
15impl Gpu {
16    pub fn new(adapter: wgpu::Adapter, instance: wgpu::Instance, device: wgpu::Device, queue: wgpu::Queue) -> Self {
17        let limits = adapter.limits();
18        Self {
19            adapter,
20            instance,
21            queue,
22            device,
23            limits,
24        }
25    }
26
27    pub fn adapter(&self) -> &wgpu::Adapter {
28        &self.adapter
29    }
30
31    pub fn instance(&self) -> &wgpu::Instance {
32        &self.instance
33    }
34
35    pub fn device(&self) -> &wgpu::Device {
36        &self.device
37    }
38
39    pub fn queue(&self) -> &wgpu::Queue {
40        &self.queue
41    }
42
43    pub fn limits(&self) -> &wgpu::Limits {
44        &self.limits
45    }
46}