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 let pipeline_compilation = if crate::host_gl::on_host_gl_context(&self.device) {
45 crate::pipeline_compiler::PipelineCompilation::Inline
46 } else {
47 pipeline_compilation
48 };
49 crate::render::GpuRendererInit {
50 device_errors: crate::device_error_sentry::DeviceErrorSentry::watching(
51 &self.device,
52 on_device_lost,
53 ),
54 device: self.device,
55 queue: self.queue,
56 surface_format: self.surface_format,
57 adapter_backend: self.adapter_backend,
58 adapter_downlevel: self.adapter_downlevel,
59 renderer_epoch,
60 pipeline_compilation,
61 }
62 }
63}
64
65pub fn optional_device_features(adapter: &wgpu::Adapter) -> wgpu::Features {
74 let mut wanted = wgpu::Features::PIPELINE_CACHE | wgpu::Features::TIMESTAMP_QUERY;
75 if matches!(
76 adapter.get_info().device_type,
77 wgpu::DeviceType::IntegratedGpu | wgpu::DeviceType::Cpu
78 ) {
79 wanted |= wgpu::Features::MAPPABLE_PRIMARY_BUFFERS;
80 }
81 adapter.features() & wanted
82}