cranpose_render_wgpu/
gpu_target.rs1use std::sync::Arc;
2
3#[derive(Clone)]
6pub struct GpuTarget {
7 pub device: Arc<wgpu::Device>,
9 pub queue: Arc<wgpu::Queue>,
11 pub surface_format: wgpu::TextureFormat,
13 pub adapter_backend: wgpu::Backend,
15 pub adapter_downlevel: wgpu::DownlevelFlags,
17}
18
19impl GpuTarget {
20 pub fn on_adapter(
23 adapter: &wgpu::Adapter,
24 device: Arc<wgpu::Device>,
25 queue: Arc<wgpu::Queue>,
26 surface_format: wgpu::TextureFormat,
27 ) -> Self {
28 Self {
29 device,
30 queue,
31 surface_format,
32 adapter_backend: adapter.get_info().backend,
33 adapter_downlevel: adapter.get_downlevel_capabilities().flags,
34 }
35 }
36
37 pub(crate) fn renderer_init(
39 self,
40 renderer_epoch: u64,
41 pipeline_compilation: crate::pipeline_compiler::PipelineCompilation,
42 on_device_lost: Option<crate::DeviceLostHandler>,
43 ) -> crate::render::GpuRendererInit {
44 crate::render::GpuRendererInit {
45 device_errors: crate::device_error_sentry::DeviceErrorSentry::watching(
46 &self.device,
47 on_device_lost,
48 ),
49 device: self.device,
50 queue: self.queue,
51 surface_format: self.surface_format,
52 adapter_backend: self.adapter_backend,
53 adapter_downlevel: self.adapter_downlevel,
54 renderer_epoch,
55 pipeline_compilation,
56 }
57 }
58}
59
60pub fn optional_device_features(adapter: &wgpu::Adapter) -> wgpu::Features {
69 let mut wanted = wgpu::Features::PIPELINE_CACHE | wgpu::Features::TIMESTAMP_QUERY;
70 if matches!(
71 adapter.get_info().device_type,
72 wgpu::DeviceType::IntegratedGpu | wgpu::DeviceType::Cpu
73 ) {
74 wanted |= wgpu::Features::MAPPABLE_PRIMARY_BUFFERS;
75 }
76 adapter.features() & wanted
77}