MCPcopy Create free account
hub / github.com/DioxusLabs/anyrender / new_from_compatible_surface

Method new_from_compatible_surface

crates/wgpu_context/src/lib.rs:31–73  ·  view source on GitHub ↗

Creates a `DeviceHandle` with `Device` that's compatible with the specified `Surface`

(
        instance: Instance,
        compatible_surface: Option<&Surface<'_>>,
        extra_features: Option<Features>,
        override_limits: Option<Limits>,
    )

Source from the content-addressed store, hash-verified

29}
30
31impl DeviceHandle {
32 /// Creates a `DeviceHandle` with `Device` that's compatible with the specified `Surface`
33 pub async fn new_from_compatible_surface(
34 instance: Instance,
35 compatible_surface: Option<&Surface<'_>>,
36 extra_features: Option<Features>,
37 override_limits: Option<Limits>,
38 ) -> Result<Self, WgpuContextError> {
39 let adapter =
40 wgpu::util::initialize_adapter_from_env_or_default(&instance, compatible_surface)
41 .await?;
42
43 // Determine features to request
44 // The user may request additional features
45 let requested_features = extra_features.unwrap_or(Features::empty());
46 let available_features = adapter.features();
47 let required_features = requested_features & available_features;
48
49 // Determine limits to request
50 // The user may override the limits
51 let required_limits = override_limits.clone().unwrap_or_else(|| Limits {
52 // Fix iOS simulator
53 max_inter_stage_shader_variables: 15,
54 ..Limits::default()
55 });
56
57 // Create the device and the queue
58 let descripter = wgpu::DeviceDescriptor {
59 label: None,
60 required_features,
61 required_limits,
62 memory_hints: MemoryHints::MemoryUsage,
63 trace: wgpu::Trace::default(),
64 experimental_features: wgpu::ExperimentalFeatures::default(),
65 };
66 let (device, queue) = adapter.request_device(&descripter).await?;
67
68 // Create the device handle and store in the pool
69 Ok(DeviceHandle {
70 instance,
71 adapter,
72 device,
73 queue,
74 })
75 }
76

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected